X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fmarkdown.ts;h=41e57d857badfb6173f9faa56d9cad9eecdfe065;hb=60520c7c852b7430e09cdc68ac7ccfe506cbf417;hp=7c4a1a8b156bee4ef372e3f167f640df97a31cca;hpb=a073c912700e1ecda70a463f334f316dc62db7a4;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/markdown.ts b/server/helpers/markdown.ts index 7c4a1a8b1..41e57d857 100644 --- a/server/helpers/markdown.ts +++ b/server/helpers/markdown.ts @@ -1,4 +1,6 @@ -import { SANITIZE_OPTIONS, TEXT_WITH_HTML_RULES } from '@shared/core-utils' +import { getSanitizeOptions, TEXT_WITH_HTML_RULES } from '@shared/core-utils' + +const sanitizeOptions = getSanitizeOptions() const sanitizeHtml = require('sanitize-html') const markdownItEmoji = require('markdown-it-emoji/light') @@ -9,6 +11,8 @@ markdownIt.enable(TEXT_WITH_HTML_RULES) markdownIt.use(markdownItEmoji) const toSafeHtml = text => { + if (!text) return '' + // Restore line feed const textWithLineFeed = text.replace(//g, '\r\n') @@ -16,15 +20,17 @@ const toSafeHtml = text => { const html = markdownIt.render(textWithLineFeed) // Convert to safe Html - return sanitizeHtml(html, SANITIZE_OPTIONS) + return sanitizeHtml(html, sanitizeOptions) } const mdToPlainText = text => { + if (!text) return '' + // Convert possible markdown (emojis, emphasis and lists) to html const html = markdownIt.render(text) // Convert to safe Html - const safeHtml = sanitizeHtml(html, SANITIZE_OPTIONS) + const safeHtml = sanitizeHtml(html, sanitizeOptions) return safeHtml.replace(/<[^>]+>/g, '') .replace(/\n$/, '')