]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/core/renderer/markdown.service.ts
Use commonjs instead of esm typescript for light emojis
[github/Chocobozzz/PeerTube.git] / client / src / app / core / renderer / markdown.service.ts
index 0c43bebabb2daaa6fcf6c44e5245f3e013946463..0e5c2ed752863221d2cffcf387a8976c1a8c009a 100644 (file)
@@ -59,20 +59,20 @@ export class MarkdownService {
 
   constructor (private htmlRenderer: HtmlRendererService) {}
 
-  textMarkdownToHTML (markdown: string, withHtml = false) {
-    if (withHtml) return this.render('textWithHTMLMarkdownIt', markdown)
+  textMarkdownToHTML (markdown: string, withHtml = false, withEmoji = false) {
+    if (withHtml) return this.render('textWithHTMLMarkdownIt', markdown, withEmoji)
 
-    return this.render('textMarkdownIt', markdown)
+    return this.render('textMarkdownIt', markdown, withEmoji)
   }
 
-  enhancedMarkdownToHTML (markdown: string, withHtml = false) {
-    if (withHtml) return this.render('enhancedWithHTMLMarkdownIt', markdown)
+  enhancedMarkdownToHTML (markdown: string, withHtml = false, withEmoji = false) {
+    if (withHtml) return this.render('enhancedWithHTMLMarkdownIt', markdown, withEmoji)
 
-    return this.render('enhancedMarkdownIt', markdown)
+    return this.render('enhancedMarkdownIt', markdown, withEmoji)
   }
 
   completeMarkdownToHTML (markdown: string) {
-    return this.render('completeMarkdownIt', markdown)
+    return this.render('completeMarkdownIt', markdown, true)
   }
 
   async processVideoTimestamps (html: string) {
@@ -83,12 +83,18 @@ export class MarkdownService {
     })
   }
 
-  private async render (name: keyof MarkdownParsers, markdown: string) {
+  private async render (name: keyof MarkdownParsers, markdown: string, withEmoji = false) {
     if (!markdown) return ''
 
     const config = this.parsersConfig[ name ]
     if (!this.markdownParsers[ name ]) {
       this.markdownParsers[ name ] = await this.createMarkdownIt(config)
+
+      if (withEmoji) {
+        // TODO: write types
+        const emoji = require('markdown-it-emoji/light')
+        this.markdownParsers[ name ].use(emoji)
+      }
     }
 
     let html = this.markdownParsers[ name ].render(markdown)