]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Add unicode emoji to markdown
authorkimsible <kimsible@users.noreply.github.com>
Sat, 8 Aug 2020 10:01:28 +0000 (12:01 +0200)
committerChocobozzz <chocobozzz@cpy.re>
Fri, 14 Aug 2020 13:03:38 +0000 (15:03 +0200)
client/package.json
client/src/app/+videos/+video-watch/comment/video-comment-add.component.html
client/src/app/+videos/+video-watch/comment/video-comment.component.ts
client/src/app/core/renderer/markdown.service.ts
client/yarn.lock
package.json
yarn.lock

index 9769cc813af27845ba44b7d7d3df234215bf08a7..11e3bf45bae212003dbbc78902a45ea3cf402a26 100644 (file)
@@ -61,6 +61,7 @@
     "@types/linkifyjs": "^2.1.2",
     "@types/lodash-es": "^4.17.0",
     "@types/markdown-it": "^10.0.1",
+    "@types/markdown-it-emoji": "^1.4.0",
     "@types/node": "^14.0.14",
     "@types/sanitize-html": "1.23.2",
     "@types/socket.io-client": "^1.4.32",
index ec8da02e277839fa46988e5da5adc88517a5ec50..b4f8bda5e30a10126196a46a7feea10ecc03304d 100644 (file)
@@ -13,6 +13,7 @@
               <li>Links</li>
               <li>Break lines</li>
               <li>Lists</li>
+              <li>Emojis</li>
             </ul>
           </div>
         </ng-template>
index fe069b54c3cb6521e0040fbe64182e8efd55c616..5491023ee5f6fd8e31a6c3b7f3d2d612cb3216fc 100644 (file)
@@ -149,7 +149,7 @@ export class VideoCommentComponent implements OnInit, OnChanges {
   }
 
   private async init () {
-    const html = await this.markdownService.textMarkdownToHTML(this.comment.text, true)
+    const html = await this.markdownService.textMarkdownToHTML(this.comment.text, true, true)
     this.sanitizedCommentHTML = await this.markdownService.processVideoTimestamps(html)
     this.newParentComments = this.parentComments.concat([ this.comment ])
 
index 0c43bebabb2daaa6fcf6c44e5245f3e013946463..2ff3de34ed5d0d7cd394af6b85f3461bd0791bd1 100644 (file)
@@ -1,4 +1,5 @@
 import * as MarkdownIt from 'markdown-it'
+import MarkdownItEmoji from 'markdown-it-emoji'
 import { buildVideoLink } from 'src/assets/player/utils'
 import { Injectable } from '@angular/core'
 import { HtmlRendererService } from './html-renderer.service'
@@ -59,20 +60,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 +84,16 @@ 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) {
+        this.markdownParsers[ name ].use(MarkdownItEmoji)
+      }
     }
 
     let html = this.markdownParsers[ name ].render(markdown)
index db52a4a544ee6b0295f7676b861d4b4709e8ad03..594ca675020a391ad28c0be947cfc83810d0b6e5 100644 (file)
   dependencies:
     "@types/node" "*"
 
-"@types/markdown-it@^10.0.1":
+"@types/markdown-it-emoji@^1.4.0":
+  version "1.4.0"
+  resolved "https://registry.yarnpkg.com/@types/markdown-it-emoji/-/markdown-it-emoji-1.4.0.tgz#2102dcb3cdaf15d7ee1c01df0fda00f61ca5fece"
+  integrity sha512-TeSq2kwZZwzt/6mfKW3FXtvVdtt9ne+Fvf5/jiBejOhGcnG3keVfsxQaHSUhy0xyHaCXDfj+kZLSPQrDtR5N4w==
+  dependencies:
+    "@types/markdown-it" "*"
+
+"@types/markdown-it@*", "@types/markdown-it@^10.0.1":
   version "10.0.1"
   resolved "https://registry.yarnpkg.com/@types/markdown-it/-/markdown-it-10.0.1.tgz#94e252ab689c8e9ceb9aff2946e0a458390105eb"
   integrity sha512-L1ibTdA5IUe/cRBlf3N3syAOBQSN1WCMGtAWir6mKxibiRl4LmpZM4jLz+7zAqiMnhQuAP1sqZOF9wXgn2kpEg==
@@ -7376,6 +7383,11 @@ map-visit@^1.0.0:
   dependencies:
     object-visit "^1.0.0"
 
+markdown-it-emoji@^1.4.0:
+  version "1.4.0"
+  resolved "https://registry.yarnpkg.com/markdown-it-emoji/-/markdown-it-emoji-1.4.0.tgz#9bee0e9a990a963ba96df6980c4fddb05dfb4dcc"
+  integrity sha1-m+4OmpkKljupbfaYDE/dsF37Tcw=
+
 markdown-it@^11.0.0:
   version "11.0.0"
   resolved "https://registry.yarnpkg.com/markdown-it/-/markdown-it-11.0.0.tgz#dbfc30363e43d756ebc52c38586b91b90046b876"
index 4e4e58878cde8331009962351cbf54e3d9fd6c87..02c456e82536edb8b0e013bd5b04bc71620c4944 100644 (file)
     "eslint-plugin-standard": "^4.0.1",
     "libxmljs": "0.19.7",
     "maildev": "^1.0.0-rc3",
+    "markdown-it-emoji": "^1.4.0",
     "marked": "^1.1.0",
     "marked-man": "^0.7.0",
     "mocha": "^8.0.1",
   "_moduleAliases": {
     "@server": "dist/server"
   },
-  "bundlewatch" : {
+  "bundlewatch": {
     "files": [
       {
         "path": "client/dist/en-US/*-es2015.js",
index 01d16b98668b88aa29e5d5b2f5fef15fad3c10e7..7714244d29601735d79082c20cee5288382beb44 100644 (file)
--- a/yarn.lock
+++ b/yarn.lock
@@ -4774,6 +4774,11 @@ make-plural@^6.2.1:
   resolved "https://registry.yarnpkg.com/make-plural/-/make-plural-6.2.1.tgz#2790af1d05fb2fc35a111ce759ffdb0aca1339a3"
   integrity sha512-AmkruwJ9EjvyTv6AM8MBMK3TAeOJvhgTv5YQXzF0EP2qawhpvMjDpHvsdOIIT0Vn+BB0+IogmYZ1z+Ulm/m0Fg==
 
+markdown-it-emoji@^1.4.0:
+  version "1.4.0"
+  resolved "https://registry.yarnpkg.com/markdown-it-emoji/-/markdown-it-emoji-1.4.0.tgz#9bee0e9a990a963ba96df6980c4fddb05dfb4dcc"
+  integrity sha1-m+4OmpkKljupbfaYDE/dsF37Tcw=
+
 marked-man@^0.7.0:
   version "0.7.0"
   resolved "https://registry.yarnpkg.com/marked-man/-/marked-man-0.7.0.tgz#220ba01d275d16f1a98e4e7fc3c5eac0630c68e4"