diff --git a/src/services/html_sanitizer.js b/src/services/html_sanitizer.js index 89727ba1e..fb396e9e8 100644 --- a/src/services/html_sanitizer.js +++ b/src/services/html_sanitizer.js @@ -5,8 +5,7 @@ const sanitizeHtml = require('sanitize-html'); function sanitize(dirtyHtml) { return sanitizeHtml(dirtyHtml, { allowedTags: [ - // h1 is removed since that should be note's title - 'h2', 'h3', 'h4', 'h5', 'h6', 'blockquote', 'p', 'a', 'ul', 'ol', + 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'blockquote', 'p', 'a', 'ul', 'ol', 'li', 'b', 'i', 'strong', 'em', 'strike', 'abbr', 'code', 'hr', 'br', 'div', 'table', 'thead', 'caption', 'tbody', 'tr', 'th', 'td', 'pre', 'section', 'img', 'figure', 'span', 'label', 'input' diff --git a/src/services/import/single.js b/src/services/import/single.js index 7270a5258..b693d82fb 100644 --- a/src/services/import/single.js +++ b/src/services/import/single.js @@ -117,6 +117,8 @@ function convertTextToHtml(text) { } function importMarkdown(taskContext, file, parentNote) { + const title = utils.getNoteTitle(file.originalname, taskContext.data.replaceUnderscoresWithSpaces); + const markdownContent = file.buffer.toString("UTF-8"); const reader = new commonmark.Parser(); @@ -127,7 +129,7 @@ function importMarkdown(taskContext, file, parentNote) { htmlContent = htmlSanitizer.sanitize(htmlContent); - const title = utils.getNoteTitle(file.originalname, taskContext.data.replaceUnderscoresWithSpaces); + htmlContent = handleH1(htmlContent, title); const {note} = noteService.createNewNote({ parentNoteId: parentNote.noteId, @@ -143,12 +145,25 @@ function importMarkdown(taskContext, file, parentNote) { return note; } +function handleH1(content, title) { + content = content.replace(/