]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/markdown.ts
Remove unnecessary NPM_RUN_BUILD_OPTS docker arg
[github/Chocobozzz/PeerTube.git] / server / helpers / markdown.ts
index 7c4a1a8b156bee4ef372e3f167f640df97a31cca..ebf479b98c1c8208f2dbf3ba3234019a29686ca7 100644 (file)
@@ -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(/<br.?\/?>/g, '\r\n')
 
@@ -16,19 +20,21 @@ 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$/, '')
-                 .replace('\n', ', ')
+                 .replace(/\n/g, ', ')
 }
 
 // ---------------------------------------------------------------------------