From 2f4eb595f61284aaa8c7c420359dd880df094e8a Mon Sep 17 00:00:00 2001 From: ehhc Date: Wed, 23 May 2018 19:47:41 +0200 Subject: [PATCH 1/7] OnBlur throws exceptions if the notetype is snippet -> Fixes #1962 --- .../main/lib/dataApi/attachmentManagement.js | 62 ++++++++++--------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/browser/main/lib/dataApi/attachmentManagement.js b/browser/main/lib/dataApi/attachmentManagement.js index 1373cf94..c83fc79d 100644 --- a/browser/main/lib/dataApi/attachmentManagement.js +++ b/browser/main/lib/dataApi/attachmentManagement.js @@ -232,39 +232,41 @@ function deleteAttachmentFolder (storageKey, noteKey) { * @param noteKey NoteKey of the current note. Is used to determine the belonging attachment folder. */ function deleteAttachmentsNotPresentInNote (markdownContent, storageKey, noteKey) { - const targetStorage = findStorage.findStorage(storageKey) - const attachmentFolder = path.join(targetStorage.path, DESTINATION_FOLDER, noteKey) - const attachmentsInNote = getAttachmentsInContent(markdownContent) - const attachmentsInNoteOnlyFileNames = [] - if (attachmentsInNote) { - for (let i = 0; i < attachmentsInNote.length; i++) { - attachmentsInNoteOnlyFileNames.push(attachmentsInNote[i].replace(new RegExp(STORAGE_FOLDER_PLACEHOLDER + escapeStringRegexp(path.sep) + noteKey + escapeStringRegexp(path.sep), 'g'), '')) - } - } - - if (fs.existsSync(attachmentFolder)) { - fs.readdir(attachmentFolder, (err, files) => { - if (err) { - console.error("Error reading directory '" + attachmentFolder + "'. Error:") - console.error(err) - return + if (storageKey && noteKey && markdownContent !== null && typeof markdownContent !== 'undefined') { + const targetStorage = findStorage.findStorage(storageKey) + const attachmentFolder = path.join(targetStorage.path, DESTINATION_FOLDER, noteKey) + const attachmentsInNote = getAttachmentsInContent(markdownContent) + const attachmentsInNoteOnlyFileNames = [] + if (attachmentsInNote) { + for (let i = 0; i < attachmentsInNote.length; i++) { + attachmentsInNoteOnlyFileNames.push(attachmentsInNote[i].replace(new RegExp(STORAGE_FOLDER_PLACEHOLDER + escapeStringRegexp(path.sep) + noteKey + escapeStringRegexp(path.sep), 'g'), '')) } - files.forEach(file => { - if (!attachmentsInNoteOnlyFileNames.includes(file)) { - const absolutePathOfFile = path.join(targetStorage.path, DESTINATION_FOLDER, noteKey, file) - fs.unlink(absolutePathOfFile, (err) => { - if (err) { - console.error("Could not delete '%s'", absolutePathOfFile) - console.error(err) - return - } - console.info("File '" + absolutePathOfFile + "' deleted because it was not included in the content of the note") - }) + } + + if (fs.existsSync(attachmentFolder)) { + fs.readdir(attachmentFolder, (err, files) => { + if (err) { + console.error("Error reading directory '" + attachmentFolder + "'. Error:") + console.error(err) + return } + files.forEach(file => { + if (!attachmentsInNoteOnlyFileNames.includes(file)) { + const absolutePathOfFile = path.join(targetStorage.path, DESTINATION_FOLDER, noteKey, file) + fs.unlink(absolutePathOfFile, (err) => { + if (err) { + console.error("Could not delete '%s'", absolutePathOfFile) + console.error(err) + return + } + console.info("File '" + absolutePathOfFile + "' deleted because it was not included in the content of the note") + }) + } + }) }) - }) - } else { - console.info("Attachment folder ('" + attachmentFolder + "') did not exist..") + } else { + console.info("Attachment folder ('" + attachmentFolder + "') did not exist..") + } } } From 8132dd68471c40b946db0371703064b71dce26ed Mon Sep 17 00:00:00 2001 From: ehhc Date: Mon, 28 May 2018 08:58:09 +0200 Subject: [PATCH 2/7] Fix for the issues raised in the code review --- .../main/lib/dataApi/attachmentManagement.js | 2 +- tests/dataApi/attachmentManagement.test.js | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/browser/main/lib/dataApi/attachmentManagement.js b/browser/main/lib/dataApi/attachmentManagement.js index c83fc79d..09673541 100644 --- a/browser/main/lib/dataApi/attachmentManagement.js +++ b/browser/main/lib/dataApi/attachmentManagement.js @@ -232,7 +232,7 @@ function deleteAttachmentFolder (storageKey, noteKey) { * @param noteKey NoteKey of the current note. Is used to determine the belonging attachment folder. */ function deleteAttachmentsNotPresentInNote (markdownContent, storageKey, noteKey) { - if (storageKey && noteKey && markdownContent !== null && typeof markdownContent !== 'undefined') { + if (storageKey != null && noteKey != null && markdownContent != null) { const targetStorage = findStorage.findStorage(storageKey) const attachmentFolder = path.join(targetStorage.path, DESTINATION_FOLDER, noteKey) const attachmentsInNote = getAttachmentsInContent(markdownContent) diff --git a/tests/dataApi/attachmentManagement.test.js b/tests/dataApi/attachmentManagement.test.js index feb9207c..1418bcfa 100644 --- a/tests/dataApi/attachmentManagement.test.js +++ b/tests/dataApi/attachmentManagement.test.js @@ -383,3 +383,35 @@ it('should test that moveAttachments returns a correct modified content version' const actualContent = systemUnderTest.moveAttachments(oldPath, newPath, oldNoteKey, newNoteKey, testInput) expect(actualContent).toBe(expectedOutput) }) + +it('should test that deleteAttachmentsNotPresentInNote does nothing if noteKey, storageKey or noteContent was null', function () { + const noteKey = null + const storageKey = null + const markdownContent = '' + + findStorage.findStorage = jest.fn() + fs.existsSync = jest.fn() + fs.readdir = jest.fn() + fs.unlink = jest.fn() + + systemUnderTest.deleteAttachmentsNotPresentInNote(markdownContent, storageKey, noteKey) + expect(fs.existsSync).not.toHaveBeenCalled() + expect(fs.readdir).not.toHaveBeenCalled() + expect(fs.unlink).not.toHaveBeenCalled() +}) + +it('should test that deleteAttachmentsNotPresentInNote does nothing if noteKey, storageKey or noteContent was undefined', function () { + const noteKey = undefined + const storageKey = undefined + const markdownContent = '' + + findStorage.findStorage = jest.fn() + fs.existsSync = jest.fn() + fs.readdir = jest.fn() + fs.unlink = jest.fn() + + systemUnderTest.deleteAttachmentsNotPresentInNote(markdownContent, storageKey, noteKey) + expect(fs.existsSync).not.toHaveBeenCalled() + expect(fs.readdir).not.toHaveBeenCalled() + expect(fs.unlink).not.toHaveBeenCalled() +}) From 225916fbba461b1ce5ad50baa52c25d3ee977fb9 Mon Sep 17 00:00:00 2001 From: ehhc Date: Mon, 28 May 2018 09:57:07 +0200 Subject: [PATCH 3/7] Fix for the test broken by the merge commit --- tests/dataApi/attachmentManagement.test.js | 66 +++++++++++----------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/tests/dataApi/attachmentManagement.test.js b/tests/dataApi/attachmentManagement.test.js index 0282e171..439a6749 100644 --- a/tests/dataApi/attachmentManagement.test.js +++ b/tests/dataApi/attachmentManagement.test.js @@ -339,6 +339,38 @@ it('should test that deleteAttachmentsNotPresentInNote does not delete reference expect(fsUnlinkCallArguments.includes(path.join(attachmentFolderPath, dummyFilesInFolder[0]))).toBe(false) }) +it('should test that deleteAttachmentsNotPresentInNote does nothing if noteKey, storageKey or noteContent was null', function () { + const noteKey = null + const storageKey = null + const markdownContent = '' + + findStorage.findStorage = jest.fn() + fs.existsSync = jest.fn() + fs.readdir = jest.fn() + fs.unlink = jest.fn() + + systemUnderTest.deleteAttachmentsNotPresentInNote(markdownContent, storageKey, noteKey) + expect(fs.existsSync).not.toHaveBeenCalled() + expect(fs.readdir).not.toHaveBeenCalled() + expect(fs.unlink).not.toHaveBeenCalled() +}) + +it('should test that deleteAttachmentsNotPresentInNote does nothing if noteKey, storageKey or noteContent was undefined', function () { + const noteKey = undefined + const storageKey = undefined + const markdownContent = '' + + findStorage.findStorage = jest.fn() + fs.existsSync = jest.fn() + fs.readdir = jest.fn() + fs.unlink = jest.fn() + + systemUnderTest.deleteAttachmentsNotPresentInNote(markdownContent, storageKey, noteKey) + expect(fs.existsSync).not.toHaveBeenCalled() + expect(fs.readdir).not.toHaveBeenCalled() + expect(fs.unlink).not.toHaveBeenCalled() +}) + it('should test that moveAttachments moves attachments only if the source folder existed', function () { fse.existsSync = jest.fn(() => false) fse.moveSync = jest.fn() @@ -395,38 +427,6 @@ it('should test that moveAttachments returns a correct modified content version' expect(actualContent).toBe(expectedOutput) }) - -it('should test that deleteAttachmentsNotPresentInNote does nothing if noteKey, storageKey or noteContent was null', function () { - const noteKey = null - const storageKey = null - const markdownContent = '' - - findStorage.findStorage = jest.fn() - fs.existsSync = jest.fn() - fs.readdir = jest.fn() - fs.unlink = jest.fn() - - systemUnderTest.deleteAttachmentsNotPresentInNote(markdownContent, storageKey, noteKey) - expect(fs.existsSync).not.toHaveBeenCalled() - expect(fs.readdir).not.toHaveBeenCalled() - expect(fs.unlink).not.toHaveBeenCalled() -}) - -it('should test that deleteAttachmentsNotPresentInNote does nothing if noteKey, storageKey or noteContent was undefined', function () { - const noteKey = undefined - const storageKey = undefined - const markdownContent = '' - - findStorage.findStorage = jest.fn() - fs.existsSync = jest.fn() - fs.readdir = jest.fn() - fs.unlink = jest.fn() - - systemUnderTest.deleteAttachmentsNotPresentInNote(markdownContent, storageKey, noteKey) - expect(fs.existsSync).not.toHaveBeenCalled() - expect(fs.readdir).not.toHaveBeenCalled() - expect(fs.unlink).not.toHaveBeenCalled() - it('should test that cloneAttachments modifies the content of the new note correctly', function () { const oldNote = {key: 'oldNoteKey', content: 'oldNoteContent', storage: 'storageKey', type: 'MARKDOWN_NOTE'} const newNote = {key: 'newNoteKey', content: 'oldNoteContent', storage: 'storageKey', type: 'MARKDOWN_NOTE'} @@ -435,6 +435,8 @@ it('should test that cloneAttachments modifies the content of the new note corre '![' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + oldNote.key + path.sep + 'image.jpg](imageName}) \n' + '[' + systemUnderTest.STORAGE_FOLDER_PLACEHOLDER + path.sep + oldNote.key + path.sep + 'pdf.pdf](pdf})' newNote.content = testInput + findStorage.findStorage = jest.fn() + findStorage.findStorage.mockReturnValue({path: 'dummyStoragePath'}) const expectedOutput = 'Test input' + From 8ccf490e9b75809db0e736696b6a2da18b4a6ec6 Mon Sep 17 00:00:00 2001 From: ehhc Date: Mon, 28 May 2018 23:05:08 +0200 Subject: [PATCH 4/7] Include markdown-it-smartArrow. Toggle it via settings and disable it by default since it might affect HTML comments in markdown --- browser/components/MarkdownEditor.js | 1 + browser/components/MarkdownPreview.js | 2 ++ browser/components/MarkdownSplitEditor.js | 1 + browser/lib/markdown.js | 5 +++++ browser/main/lib/ConfigManager.js | 1 + browser/main/modals/PreferencesModal/UiTab.js | 11 +++++++++++ locales/da.json | 3 ++- locales/de.json | 3 ++- locales/en.json | 3 ++- locales/es-ES.json | 3 ++- locales/fa.json | 3 ++- locales/fr.json | 3 ++- locales/hu.json | 3 ++- locales/it.json | 3 ++- locales/ja.json | 3 ++- locales/ko.json | 3 ++- locales/no.json | 3 ++- locales/pl.json | 3 ++- locales/pt-BR.json | 3 ++- locales/pt-PT.json | 3 ++- locales/ru.json | 3 ++- locales/sq.json | 3 ++- locales/zh-CN.json | 3 ++- locales/zh-TW.json | 3 ++- package.json | 1 + yarn.lock | 4 ++++ 26 files changed, 62 insertions(+), 18 deletions(-) diff --git a/browser/components/MarkdownEditor.js b/browser/components/MarkdownEditor.js index 2bd5d951..b4040505 100644 --- a/browser/components/MarkdownEditor.js +++ b/browser/components/MarkdownEditor.js @@ -283,6 +283,7 @@ class MarkdownEditor extends React.Component { indentSize={editorIndentSize} scrollPastEnd={config.preview.scrollPastEnd} smartQuotes={config.preview.smartQuotes} + smartArrows={config.previw.smartArrows} breaks={config.preview.breaks} sanitize={config.preview.sanitize} ref='preview' diff --git a/browser/components/MarkdownPreview.js b/browser/components/MarkdownPreview.js index 69340ae5..d8909779 100755 --- a/browser/components/MarkdownPreview.js +++ b/browser/components/MarkdownPreview.js @@ -336,6 +336,7 @@ export default class MarkdownPreview extends React.Component { if (prevProps.value !== this.props.value) this.rewriteIframe() if (prevProps.smartQuotes !== this.props.smartQuotes || prevProps.sanitize !== this.props.sanitize || + prevProps.smartArrows !== this.props.smartArrows || prevProps.breaks !== this.props.breaks) { this.initMarkdown() this.rewriteIframe() @@ -590,5 +591,6 @@ MarkdownPreview.propTypes = { showCopyNotification: PropTypes.bool, storagePath: PropTypes.string, smartQuotes: PropTypes.bool, + smartArrows: PropTypes.bool, breaks: PropTypes.bool } diff --git a/browser/components/MarkdownSplitEditor.js b/browser/components/MarkdownSplitEditor.js index 2bee5c24..45a4cce4 100644 --- a/browser/components/MarkdownSplitEditor.js +++ b/browser/components/MarkdownSplitEditor.js @@ -131,6 +131,7 @@ class MarkdownSplitEditor extends React.Component { lineNumber={config.preview.lineNumber} scrollPastEnd={config.preview.scrollPastEnd} smartQuotes={config.preview.smartQuotes} + smartArrows={config.preview.smartArrows} breaks={config.preview.breaks} sanitize={config.preview.sanitize} ref='preview' diff --git a/browser/lib/markdown.js b/browser/lib/markdown.js index 70f95024..4dafa4a3 100644 --- a/browser/lib/markdown.js +++ b/browser/lib/markdown.js @@ -2,6 +2,7 @@ import markdownit from 'markdown-it' import sanitize from './markdown-it-sanitize-html' import emoji from 'markdown-it-emoji' import math from '@rokt33r/markdown-it-math' +import smartArrows from 'markdown-it-smartarrows' import _ from 'lodash' import ConfigManager from 'browser/main/lib/ConfigManager' import katex from 'katex' @@ -214,6 +215,10 @@ class Markdown { return true }) + if (config.preview.smartArrows) { + this.md.use(smartArrows) + } + // Add line number attribute for scrolling const originalRender = this.md.renderer.render this.md.renderer.render = (tokens, options, env) => { diff --git a/browser/main/lib/ConfigManager.js b/browser/main/lib/ConfigManager.js index 228692d6..5abebf5a 100644 --- a/browser/main/lib/ConfigManager.js +++ b/browser/main/lib/ConfigManager.js @@ -59,6 +59,7 @@ export const DEFAULT_CONFIG = { scrollPastEnd: false, smartQuotes: true, breaks: true, + smartArrows: false, sanitize: 'STRICT' // 'STRICT', 'ALLOW_STYLES', 'NONE' }, blog: { diff --git a/browser/main/modals/PreferencesModal/UiTab.js b/browser/main/modals/PreferencesModal/UiTab.js index e059d72d..39228b37 100644 --- a/browser/main/modals/PreferencesModal/UiTab.js +++ b/browser/main/modals/PreferencesModal/UiTab.js @@ -98,6 +98,7 @@ class UiTab extends React.Component { scrollPastEnd: this.refs.previewScrollPastEnd.checked, smartQuotes: this.refs.previewSmartQuotes.checked, breaks: this.refs.previewBreaks.checked, + smartArrows: this.refs.previewSmartArrows.checked, sanitize: this.refs.previewSanitize.value } } @@ -487,6 +488,16 @@ class UiTab extends React.Component { {i18n.__('Render newlines in Markdown paragraphs as
')} +
+ +
diff --git a/locales/da.json b/locales/da.json index 314058cb..6a059cce 100644 --- a/locales/da.json +++ b/locales/da.json @@ -150,5 +150,6 @@ "Sanitization": "Sanitization", "Only allow secure html tags (recommended)": "Only allow secure html tags (recommended)", "Allow styles": "Allow styles", - "Allow dangerous html tags": "Allow dangerous html tags" + "Allow dangerous html tags": "Allow dangerous html tags", + "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown." } diff --git a/locales/de.json b/locales/de.json index 7e7da1f3..69ef2aee 100644 --- a/locales/de.json +++ b/locales/de.json @@ -205,5 +205,6 @@ "Unnamed": "Unbenannt", "Rename": "Umbenennen", "Folder Name": "Ordnername", - "No tags": "Keine Tags" + "No tags": "Keine Tags", + "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown." } diff --git a/locales/en.json b/locales/en.json index e40035ae..37ce250a 100644 --- a/locales/en.json +++ b/locales/en.json @@ -174,5 +174,6 @@ "Only allow secure html tags (recommended)": "Only allow secure html tags (recommended)", "Render newlines in Markdown paragraphs as
": "Render newlines in Markdown paragraphs as
", "Allow styles": "Allow styles", - "Allow dangerous html tags": "Allow dangerous html tags" + "Allow dangerous html tags": "Allow dangerous html tags", + "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown." } diff --git a/locales/es-ES.json b/locales/es-ES.json index 0fa27713..f277b554 100644 --- a/locales/es-ES.json +++ b/locales/es-ES.json @@ -150,5 +150,6 @@ "Sanitization": "Saneamiento", "Only allow secure html tags (recommended)": "Solo permitir etiquetas html seguras (recomendado)", "Allow styles": "Permitir estilos", - "Allow dangerous html tags": "Permitir etiquetas html peligrosas" + "Allow dangerous html tags": "Permitir etiquetas html peligrosas", + "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown." } diff --git a/locales/fa.json b/locales/fa.json index 125056a6..1037ea58 100644 --- a/locales/fa.json +++ b/locales/fa.json @@ -153,5 +153,6 @@ "Sanitization": "پاکسازی کردن", "Only allow secure html tags (recommended)": "(فقط تگ های امن اچ تی ام ال مجاز اند.(پیشنهاد میشود", "Allow styles": "حالت های مجاز", - "Allow dangerous html tags": "تگ های خطرناک اچ‌ تی ام ال مجاز اند" + "Allow dangerous html tags": "تگ های خطرناک اچ‌ تی ام ال مجاز اند", + "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown." } \ No newline at end of file diff --git a/locales/fr.json b/locales/fr.json index d285a29c..2a51256f 100644 --- a/locales/fr.json +++ b/locales/fr.json @@ -150,5 +150,6 @@ "Sanitization": "Sanitization", "Only allow secure html tags (recommended)": "Only allow secure html tags (recommended)", "Allow styles": "Allow styles", - "Allow dangerous html tags": "Allow dangerous html tags" + "Allow dangerous html tags": "Allow dangerous html tags", + "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown." } diff --git a/locales/hu.json b/locales/hu.json index d02a6810..90ee64b6 100644 --- a/locales/hu.json +++ b/locales/hu.json @@ -174,5 +174,6 @@ "Only allow secure html tags (recommended)": "Csak a biztonságos html tag-ek engedélyezése (ajánlott)", "Render newlines in Markdown paragraphs as
": "Az újsor karaktert
soremelésként jelenítse meg a Markdown jegyzetekben", "Allow styles": "Stílusok engedélyezése", - "Allow dangerous html tags": "Veszélyes html tag-ek engedélyezése" + "Allow dangerous html tags": "Veszélyes html tag-ek engedélyezése", + "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown." } diff --git a/locales/it.json b/locales/it.json index 10c97c94..13a6ded3 100644 --- a/locales/it.json +++ b/locales/it.json @@ -153,5 +153,6 @@ "Sanitization": "Bonifica", "Only allow secure html tags (recommended)": "Consenti solo tag HTML sicuri (raccomandato)", "Allow styles": "Consenti stili", - "Allow dangerous html tags": "Consenti tag HTML pericolosi" + "Allow dangerous html tags": "Consenti tag HTML pericolosi", + "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown." }" diff --git a/locales/ja.json b/locales/ja.json index 987f11e5..5320a68f 100644 --- a/locales/ja.json +++ b/locales/ja.json @@ -150,5 +150,6 @@ "Sanitization": "サニタイズ", "Only allow secure html tags (recommended)": "安全なHTMLタグのみ利用を許可する(推奨)", "Allow styles": "スタイルを許可する", - "Allow dangerous html tags": "安全でないHTMLタグの利用を許可する" + "Allow dangerous html tags": "安全でないHTMLタグの利用を許可する", + "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown." } diff --git a/locales/ko.json b/locales/ko.json index 3360f269..3121a581 100644 --- a/locales/ko.json +++ b/locales/ko.json @@ -156,5 +156,6 @@ "Sanitization": "허용 태그 범위", "Only allow secure html tags (recommended)": "안전한 HTML 태그만 허용 (추천)", "Allow styles": "style 태그, 속성까지 허용", - "Allow dangerous html tags": "모든 위험한 태그 허용" + "Allow dangerous html tags": "모든 위험한 태그 허용", + "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown." } diff --git a/locales/no.json b/locales/no.json index 1ec74f0e..5ccd343e 100644 --- a/locales/no.json +++ b/locales/no.json @@ -149,5 +149,6 @@ "Sanitization": "Sanitization", "Only allow secure html tags (recommended)": "Only allow secure html tags (recommended)", "Allow styles": "Allow styles", - "Allow dangerous html tags": "Allow dangerous html tags" + "Allow dangerous html tags": "Allow dangerous html tags", + "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown." } diff --git a/locales/pl.json b/locales/pl.json index 1ec74f0e..5ccd343e 100644 --- a/locales/pl.json +++ b/locales/pl.json @@ -149,5 +149,6 @@ "Sanitization": "Sanitization", "Only allow secure html tags (recommended)": "Only allow secure html tags (recommended)", "Allow styles": "Allow styles", - "Allow dangerous html tags": "Allow dangerous html tags" + "Allow dangerous html tags": "Allow dangerous html tags", + "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown." } diff --git a/locales/pt-BR.json b/locales/pt-BR.json index 1f8361af..c6f1c994 100644 --- a/locales/pt-BR.json +++ b/locales/pt-BR.json @@ -149,5 +149,6 @@ "Sanitization": "Sanitização", "Only allow secure html tags (recommended)": "Permitir apenas tags html seguras (recomendado)", "Allow styles": "Permitir estilos", - "Allow dangerous html tags": "Permitir tags html perigosas" + "Allow dangerous html tags": "Permitir tags html perigosas", + "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown." } diff --git a/locales/pt-PT.json b/locales/pt-PT.json index 1ec74f0e..5ccd343e 100644 --- a/locales/pt-PT.json +++ b/locales/pt-PT.json @@ -149,5 +149,6 @@ "Sanitization": "Sanitization", "Only allow secure html tags (recommended)": "Only allow secure html tags (recommended)", "Allow styles": "Allow styles", - "Allow dangerous html tags": "Allow dangerous html tags" + "Allow dangerous html tags": "Allow dangerous html tags", + "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown." } diff --git a/locales/ru.json b/locales/ru.json index 0f3696d2..a81b5f12 100644 --- a/locales/ru.json +++ b/locales/ru.json @@ -146,5 +146,6 @@ "Russian": "Русский", "Editor Rulers": "Editor Rulers", "Enable": "Enable", - "Disable": "Disable" + "Disable": "Disable", + "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown." } diff --git a/locales/sq.json b/locales/sq.json index 01a6fe0b..ae59157c 100644 --- a/locales/sq.json +++ b/locales/sq.json @@ -148,5 +148,6 @@ "Sanitization": "Sanitization", "Only allow secure html tags (recommended)": "Only allow secure html tags (recommended)", "Allow styles": "Allow styles", - "Allow dangerous html tags": "Allow dangerous html tags" + "Allow dangerous html tags": "Allow dangerous html tags", + "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown." } diff --git a/locales/zh-CN.json b/locales/zh-CN.json index b736520d..badd3630 100755 --- a/locales/zh-CN.json +++ b/locales/zh-CN.json @@ -148,5 +148,6 @@ "Sanitization": "代码处理", "Only allow secure html tags (recommended)": "只允许安全的html标签(推荐)", "Allow styles": "允许样式", - "Allow dangerous html tags": "允许危险的html标签" + "Allow dangerous html tags": "允许危险的html标签", + "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown." } diff --git a/locales/zh-TW.json b/locales/zh-TW.json index bc60cfcc..ed9b4c08 100755 --- a/locales/zh-TW.json +++ b/locales/zh-TW.json @@ -148,5 +148,6 @@ "Sanitization": "過濾 HTML 程式碼", "Only allow secure html tags (recommended)": "只允許安全的 HTML 標籤 (建議)", "Allow styles": "允許樣式", - "Allow dangerous html tags": "允許危險的 HTML 標籤" + "Allow dangerous html tags": "允許危險的 HTML 標籤", + "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown.": "Convert textual arrows to beautiful signs. ⚠ This will interfere with using HTML comments in your Markdown." } diff --git a/package.json b/package.json index d0368702..0822d967 100644 --- a/package.json +++ b/package.json @@ -79,6 +79,7 @@ "markdown-it-multimd-table": "^2.0.1", "markdown-it-named-headers": "^0.0.4", "markdown-it-plantuml": "^0.3.0", + "markdown-it-smartarrows": "^1.0.1", "md5": "^2.0.0", "mdurl": "^1.0.1", "moment": "^2.10.3", diff --git a/yarn.lock b/yarn.lock index fcf87c4a..bf7b2ed1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5430,6 +5430,10 @@ markdown-it-plantuml@^0.3.0: version "0.3.2" resolved "https://registry.yarnpkg.com/markdown-it-plantuml/-/markdown-it-plantuml-0.3.2.tgz#f93a49bdfc8417b0df3c88700445f53487e57356" +markdown-it-smartarrows@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/markdown-it-smartarrows/-/markdown-it-smartarrows-1.0.1.tgz#b570e9c0ff9812e0db6ace19afa5ba12b64bb9a7" + markdown-it@^5.0.3: version "5.1.0" resolved "https://registry.yarnpkg.com/markdown-it/-/markdown-it-5.1.0.tgz#25286b8465bac496f3f1b77eed544643e9bd718d" From 03293c0d258648a18509c1a6a7ca78792d5f44ce Mon Sep 17 00:00:00 2001 From: kawmra Date: Sat, 2 Jun 2018 22:59:49 +0900 Subject: [PATCH 5/7] Fix conflict of yarn.lock --- yarn.lock | 4 ---- 1 file changed, 4 deletions(-) diff --git a/yarn.lock b/yarn.lock index a0d630dd..91e0d436 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2777,11 +2777,7 @@ eslint-plugin-promise@~3.4.0: version "3.4.2" resolved "https://registry.yarnpkg.com/eslint-plugin-promise/-/eslint-plugin-promise-3.4.2.tgz#1be2793eafe2d18b5b123b8136c269f804fe7122" -<<<<<<< HEAD eslint-plugin-react@^7.8.2: -======= -eslint-plugin-react@^7.2.0: ->>>>>>> ca0b03e97ce59824c9730f08c15590c5f31ebfb0 version "7.8.2" resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-7.8.2.tgz#e95c9c47fece55d2303d1a67c9d01b930b88a51d" dependencies: From 30378eeb50ba08ad51f2ada5c2651ba66ce69ba0 Mon Sep 17 00:00:00 2001 From: kawmra Date: Sat, 2 Jun 2018 23:01:52 +0900 Subject: [PATCH 6/7] Remove unnecessary lines --- yarn.lock | 6 ------ 1 file changed, 6 deletions(-) diff --git a/yarn.lock b/yarn.lock index 91e0d436..65a68784 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2382,12 +2382,6 @@ doctrine@^2.0.0, doctrine@^2.0.2: dependencies: esutils "^2.0.2" -doctrine@^2.0.2: - version "2.1.0" - resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-2.1.0.tgz#5cd01fc101621b42c4cd7f5d1a66243716d3f39d" - dependencies: - esutils "^2.0.2" - dom-serializer@0: version "0.1.0" resolved "https://registry.yarnpkg.com/dom-serializer/-/dom-serializer-0.1.0.tgz#073c697546ce0780ce23be4a28e293e40bc30c82" From b526d489460e22cba9f5db6105068b243b30531f Mon Sep 17 00:00:00 2001 From: ehhc Date: Tue, 5 Jun 2018 11:16:50 +0200 Subject: [PATCH 7/7] CodeReview --- .../main/lib/dataApi/attachmentManagement.js | 64 +++++++++---------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/browser/main/lib/dataApi/attachmentManagement.js b/browser/main/lib/dataApi/attachmentManagement.js index a93fc8a5..077f02d8 100644 --- a/browser/main/lib/dataApi/attachmentManagement.js +++ b/browser/main/lib/dataApi/attachmentManagement.js @@ -245,41 +245,41 @@ function deleteAttachmentFolder (storageKey, noteKey) { * @param noteKey NoteKey of the current note. Is used to determine the belonging attachment folder. */ function deleteAttachmentsNotPresentInNote (markdownContent, storageKey, noteKey) { - if (storageKey != null && noteKey != null && markdownContent != null) { - const targetStorage = findStorage.findStorage(storageKey) - const attachmentFolder = path.join(targetStorage.path, DESTINATION_FOLDER, noteKey) - const attachmentsInNote = getAttachmentsInContent(markdownContent) - const attachmentsInNoteOnlyFileNames = [] - if (attachmentsInNote) { - for (let i = 0; i < attachmentsInNote.length; i++) { - attachmentsInNoteOnlyFileNames.push(attachmentsInNote[i].replace(new RegExp(STORAGE_FOLDER_PLACEHOLDER + escapeStringRegexp(path.sep) + noteKey + escapeStringRegexp(path.sep), 'g'), '')) + if (storageKey == null || noteKey == null || markdownContent == null) { + return + } + const targetStorage = findStorage.findStorage(storageKey) + const attachmentFolder = path.join(targetStorage.path, DESTINATION_FOLDER, noteKey) + const attachmentsInNote = getAttachmentsInContent(markdownContent) + const attachmentsInNoteOnlyFileNames = [] + if (attachmentsInNote) { + for (let i = 0; i < attachmentsInNote.length; i++) { + attachmentsInNoteOnlyFileNames.push(attachmentsInNote[i].replace(new RegExp(STORAGE_FOLDER_PLACEHOLDER + escapeStringRegexp(path.sep) + noteKey + escapeStringRegexp(path.sep), 'g'), '')) + } + } + if (fs.existsSync(attachmentFolder)) { + fs.readdir(attachmentFolder, (err, files) => { + if (err) { + console.error('Error reading directory \'' + attachmentFolder + '\'. Error:') + console.error(err) + return } - } - - if (fs.existsSync(attachmentFolder)) { - fs.readdir(attachmentFolder, (err, files) => { - if (err) { - console.error("Error reading directory '" + attachmentFolder + "'. Error:") - console.error(err) - return + files.forEach(file => { + if (!attachmentsInNoteOnlyFileNames.includes(file)) { + const absolutePathOfFile = path.join(targetStorage.path, DESTINATION_FOLDER, noteKey, file) + fs.unlink(absolutePathOfFile, (err) => { + if (err) { + console.error('Could not delete \'%s\'', absolutePathOfFile) + console.error(err) + return + } + console.info('File \'' + absolutePathOfFile + '\' deleted because it was not included in the content of the note') + }) } - files.forEach(file => { - if (!attachmentsInNoteOnlyFileNames.includes(file)) { - const absolutePathOfFile = path.join(targetStorage.path, DESTINATION_FOLDER, noteKey, file) - fs.unlink(absolutePathOfFile, (err) => { - if (err) { - console.error("Could not delete '%s'", absolutePathOfFile) - console.error(err) - return - } - console.info("File '" + absolutePathOfFile + "' deleted because it was not included in the content of the note") - }) - } - }) }) - } else { - console.info("Attachment folder ('" + attachmentFolder + "') did not exist..") - } + }) + } else { + console.debug('Attachment folder (\'' + attachmentFolder + '\') did not exist..') } }