From 59d618f06b498a5c3d416aa18874b9c7dea47b31 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 25 Feb 2024 08:12:07 +0200 Subject: [PATCH] server-ts: Port services/import/markdown --- src/routes/api/other.js | 2 +- src/services/import/markdown.js | 18 ------------------ src/services/import/markdown.ts | 17 +++++++++++++++++ src/services/import/single.js | 2 +- src/services/import/zip.js | 2 +- 5 files changed, 20 insertions(+), 21 deletions(-) delete mode 100644 src/services/import/markdown.js create mode 100644 src/services/import/markdown.ts diff --git a/src/routes/api/other.js b/src/routes/api/other.js index a05600a56..437636e8e 100644 --- a/src/routes/api/other.js +++ b/src/routes/api/other.js @@ -1,5 +1,5 @@ const becca = require('../../becca/becca'); -const markdownService = require('../../services/import/markdown.js'); +const markdownService = require('../../services/import/markdown'); function getIconUsage() { const iconClassToCountMap = {}; diff --git a/src/services/import/markdown.js b/src/services/import/markdown.js deleted file mode 100644 index 745f30847..000000000 --- a/src/services/import/markdown.js +++ /dev/null @@ -1,18 +0,0 @@ -"use strict"; - -const marked = require("marked"); -const htmlSanitizer = require('../html_sanitizer'); -const importUtils = require('./utils'); - -function renderToHtml(content, title) { - const html = marked.parse(content, { - mangle: false, - headerIds: false - }); - const h1Handled = importUtils.handleH1(html, title); // h1 handling needs to come before sanitization - return htmlSanitizer.sanitize(h1Handled); -} - -module.exports = { - renderToHtml -}; diff --git a/src/services/import/markdown.ts b/src/services/import/markdown.ts new file mode 100644 index 000000000..ab3391153 --- /dev/null +++ b/src/services/import/markdown.ts @@ -0,0 +1,17 @@ +"use strict"; + +import marked = require("marked"); +import htmlSanitizer = require('../html_sanitizer'); +import importUtils = require('./utils'); + +function renderToHtml(content: string, title: string) { + const html = marked.parse(content, { + async: false + }); // FIXME: mangle and headerIds does not seem to exist in marked + const h1Handled = importUtils.handleH1(html, title); // h1 handling needs to come before sanitization + return htmlSanitizer.sanitize(h1Handled); +} + +export = { + renderToHtml +}; diff --git a/src/services/import/single.js b/src/services/import/single.js index 454406f93..31928e7fe 100644 --- a/src/services/import/single.js +++ b/src/services/import/single.js @@ -3,7 +3,7 @@ const noteService = require('../../services/notes'); const imageService = require('../../services/image'); const protectedSessionService = require('../protected_session'); -const markdownService = require('./markdown.js'); +const markdownService = require('./markdown'); const mimeService = require('./mime'); const utils = require('../../services/utils'); const importUtils = require('./utils'); diff --git a/src/services/import/zip.js b/src/services/import/zip.js index 041850ad8..9d35c539a 100644 --- a/src/services/import/zip.js +++ b/src/services/import/zip.js @@ -14,7 +14,7 @@ const yauzl = require("yauzl"); const htmlSanitizer = require('../html_sanitizer'); const becca = require('../../becca/becca'); const BAttachment = require('../../becca/entities/battachment'); -const markdownService = require('./markdown.js'); +const markdownService = require('./markdown'); /** * @param {TaskContext} taskContext