From 09188bed4856450e21b047ac62870c52e8b77636 Mon Sep 17 00:00:00 2001 From: ehhc Date: Mon, 30 Jul 2018 18:09:02 +0200 Subject: [PATCH] might fixes #1786 --> export attachments for markdown notes --- browser/components/MarkdownPreview.js | 15 ++++++++++++++- tests/dataApi/attachmentManagement.test.js | 15 +++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/browser/components/MarkdownPreview.js b/browser/components/MarkdownPreview.js index 1cec5cdd4..2e80acf6e 100755 --- a/browser/components/MarkdownPreview.js +++ b/browser/components/MarkdownPreview.js @@ -232,7 +232,20 @@ export default class MarkdownPreview extends React.Component { } handleSaveAsMd () { - this.exportAsDocument('md') + this.exportAsDocument('md', (noteContent, exportTasks) => { + let result = noteContent + if (this.props && this.props.storagePath && this.props.noteKey) { + const attachmentsAbsolutePaths = attachmentManagement.getAbsolutePathsOfAttachmentsInContent(noteContent, this.props.storagePath) + attachmentsAbsolutePaths.forEach((attachment) => { + exportTasks.push({ + src: attachment, + dst: attachmentManagement.DESTINATION_FOLDER + }) + }) + result = attachmentManagement.removeStorageAndNoteReferences(noteContent, this.props.noteKey) + } + return result + }) } handleSaveAsHtml () { diff --git a/tests/dataApi/attachmentManagement.test.js b/tests/dataApi/attachmentManagement.test.js index 853e0431d..a4cc80820 100644 --- a/tests/dataApi/attachmentManagement.test.js +++ b/tests/dataApi/attachmentManagement.test.js @@ -319,6 +319,21 @@ it('should remove the all ":storage" and noteKey references', function () { expect(actual).toEqual(expectedOutput) }) +it('should make sure that "removeStorageAndNoteReferences" works with markdown content as well', function () { + const noteKey = 'noteKey' + const testInput = + 'Test input' + + '![' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + noteKey + path.sep + 'image.jpg](imageName}) \n' + + '[' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + noteKey + path.sep + 'pdf.pdf](pdf})' + + const expectedOutput = + 'Test input' + + '![' + systemUnderTest.DESTINATION_FOLDER + path.sep + 'image.jpg](imageName}) \n' + + '[' + systemUnderTest.DESTINATION_FOLDER + path.sep + 'pdf.pdf](pdf})' + const actual = systemUnderTest.removeStorageAndNoteReferences(testInput, noteKey) + expect(actual).toEqual(expectedOutput) +}) + it('should delete the correct attachment folder if a note is deleted', function () { const dummyStorage = {path: 'dummyStoragePath'} const storageKey = 'storageKey'