aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorkimsible <kimsible@users.noreply.github.com>2020-08-08 12:01:28 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-08-14 15:03:38 +0200
commit0672dc769b6ee42b4357748c62aaeabf8801c472 (patch)
tree54b206fcbe25129ee57a81c6130222a28775fe43
parent438c256b2672fa9539b703e6f28d4b70ef3dccfb (diff)
downloadPeerTube-0672dc769b6ee42b4357748c62aaeabf8801c472.tar.gz
PeerTube-0672dc769b6ee42b4357748c62aaeabf8801c472.tar.zst
PeerTube-0672dc769b6ee42b4357748c62aaeabf8801c472.zip
Add unicode emoji to markdown
-rw-r--r--client/package.json1
-rw-r--r--client/src/app/+videos/+video-watch/comment/video-comment-add.component.html1
-rw-r--r--client/src/app/+videos/+video-watch/comment/video-comment.component.ts2
-rw-r--r--client/src/app/core/renderer/markdown.service.ts21
-rw-r--r--client/yarn.lock14
-rw-r--r--package.json3
-rw-r--r--yarn.lock5
7 files changed, 36 insertions, 11 deletions
diff --git a/client/package.json b/client/package.json
index 9769cc813..11e3bf45b 100644
--- a/client/package.json
+++ b/client/package.json
@@ -61,6 +61,7 @@
61 "@types/linkifyjs": "^2.1.2", 61 "@types/linkifyjs": "^2.1.2",
62 "@types/lodash-es": "^4.17.0", 62 "@types/lodash-es": "^4.17.0",
63 "@types/markdown-it": "^10.0.1", 63 "@types/markdown-it": "^10.0.1",
64 "@types/markdown-it-emoji": "^1.4.0",
64 "@types/node": "^14.0.14", 65 "@types/node": "^14.0.14",
65 "@types/sanitize-html": "1.23.2", 66 "@types/sanitize-html": "1.23.2",
66 "@types/socket.io-client": "^1.4.32", 67 "@types/socket.io-client": "^1.4.32",
diff --git a/client/src/app/+videos/+video-watch/comment/video-comment-add.component.html b/client/src/app/+videos/+video-watch/comment/video-comment-add.component.html
index ec8da02e2..b4f8bda5e 100644
--- a/client/src/app/+videos/+video-watch/comment/video-comment-add.component.html
+++ b/client/src/app/+videos/+video-watch/comment/video-comment-add.component.html
@@ -13,6 +13,7 @@
13 <li>Links</li> 13 <li>Links</li>
14 <li>Break lines</li> 14 <li>Break lines</li>
15 <li>Lists</li> 15 <li>Lists</li>
16 <li>Emojis</li>
16 </ul> 17 </ul>
17 </div> 18 </div>
18 </ng-template> 19 </ng-template>
diff --git a/client/src/app/+videos/+video-watch/comment/video-comment.component.ts b/client/src/app/+videos/+video-watch/comment/video-comment.component.ts
index fe069b54c..5491023ee 100644
--- a/client/src/app/+videos/+video-watch/comment/video-comment.component.ts
+++ b/client/src/app/+videos/+video-watch/comment/video-comment.component.ts
@@ -149,7 +149,7 @@ export class VideoCommentComponent implements OnInit, OnChanges {
149 } 149 }
150 150
151 private async init () { 151 private async init () {
152 const html = await this.markdownService.textMarkdownToHTML(this.comment.text, true) 152 const html = await this.markdownService.textMarkdownToHTML(this.comment.text, true, true)
153 this.sanitizedCommentHTML = await this.markdownService.processVideoTimestamps(html) 153 this.sanitizedCommentHTML = await this.markdownService.processVideoTimestamps(html)
154 this.newParentComments = this.parentComments.concat([ this.comment ]) 154 this.newParentComments = this.parentComments.concat([ this.comment ])
155 155
diff --git a/client/src/app/core/renderer/markdown.service.ts b/client/src/app/core/renderer/markdown.service.ts
index 0c43bebab..2ff3de34e 100644
--- a/client/src/app/core/renderer/markdown.service.ts
+++ b/client/src/app/core/renderer/markdown.service.ts
@@ -1,4 +1,5 @@
1import * as MarkdownIt from 'markdown-it' 1import * as MarkdownIt from 'markdown-it'
2import MarkdownItEmoji from 'markdown-it-emoji'
2import { buildVideoLink } from 'src/assets/player/utils' 3import { buildVideoLink } from 'src/assets/player/utils'
3import { Injectable } from '@angular/core' 4import { Injectable } from '@angular/core'
4import { HtmlRendererService } from './html-renderer.service' 5import { HtmlRendererService } from './html-renderer.service'
@@ -59,20 +60,20 @@ export class MarkdownService {
59 60
60 constructor (private htmlRenderer: HtmlRendererService) {} 61 constructor (private htmlRenderer: HtmlRendererService) {}
61 62
62 textMarkdownToHTML (markdown: string, withHtml = false) { 63 textMarkdownToHTML (markdown: string, withHtml = false, withEmoji = false) {
63 if (withHtml) return this.render('textWithHTMLMarkdownIt', markdown) 64 if (withHtml) return this.render('textWithHTMLMarkdownIt', markdown, withEmoji)
64 65
65 return this.render('textMarkdownIt', markdown) 66 return this.render('textMarkdownIt', markdown, withEmoji)
66 } 67 }
67 68
68 enhancedMarkdownToHTML (markdown: string, withHtml = false) { 69 enhancedMarkdownToHTML (markdown: string, withHtml = false, withEmoji = false) {
69 if (withHtml) return this.render('enhancedWithHTMLMarkdownIt', markdown) 70 if (withHtml) return this.render('enhancedWithHTMLMarkdownIt', markdown, withEmoji)
70 71
71 return this.render('enhancedMarkdownIt', markdown) 72 return this.render('enhancedMarkdownIt', markdown, withEmoji)
72 } 73 }
73 74
74 completeMarkdownToHTML (markdown: string) { 75 completeMarkdownToHTML (markdown: string) {
75 return this.render('completeMarkdownIt', markdown) 76 return this.render('completeMarkdownIt', markdown, true)
76 } 77 }
77 78
78 async processVideoTimestamps (html: string) { 79 async processVideoTimestamps (html: string) {
@@ -83,12 +84,16 @@ export class MarkdownService {
83 }) 84 })
84 } 85 }
85 86
86 private async render (name: keyof MarkdownParsers, markdown: string) { 87 private async render (name: keyof MarkdownParsers, markdown: string, withEmoji = false) {
87 if (!markdown) return '' 88 if (!markdown) return ''
88 89
89 const config = this.parsersConfig[ name ] 90 const config = this.parsersConfig[ name ]
90 if (!this.markdownParsers[ name ]) { 91 if (!this.markdownParsers[ name ]) {
91 this.markdownParsers[ name ] = await this.createMarkdownIt(config) 92 this.markdownParsers[ name ] = await this.createMarkdownIt(config)
93
94 if (withEmoji) {
95 this.markdownParsers[ name ].use(MarkdownItEmoji)
96 }
92 } 97 }
93 98
94 let html = this.markdownParsers[ name ].render(markdown) 99 let html = this.markdownParsers[ name ].render(markdown)
diff --git a/client/yarn.lock b/client/yarn.lock
index db52a4a54..594ca6750 100644
--- a/client/yarn.lock
+++ b/client/yarn.lock
@@ -1569,7 +1569,14 @@
1569 dependencies: 1569 dependencies:
1570 "@types/node" "*" 1570 "@types/node" "*"
1571 1571
1572"@types/markdown-it@^10.0.1": 1572"@types/markdown-it-emoji@^1.4.0":
1573 version "1.4.0"
1574 resolved "https://registry.yarnpkg.com/@types/markdown-it-emoji/-/markdown-it-emoji-1.4.0.tgz#2102dcb3cdaf15d7ee1c01df0fda00f61ca5fece"
1575 integrity sha512-TeSq2kwZZwzt/6mfKW3FXtvVdtt9ne+Fvf5/jiBejOhGcnG3keVfsxQaHSUhy0xyHaCXDfj+kZLSPQrDtR5N4w==
1576 dependencies:
1577 "@types/markdown-it" "*"
1578
1579"@types/markdown-it@*", "@types/markdown-it@^10.0.1":
1573 version "10.0.1" 1580 version "10.0.1"
1574 resolved "https://registry.yarnpkg.com/@types/markdown-it/-/markdown-it-10.0.1.tgz#94e252ab689c8e9ceb9aff2946e0a458390105eb" 1581 resolved "https://registry.yarnpkg.com/@types/markdown-it/-/markdown-it-10.0.1.tgz#94e252ab689c8e9ceb9aff2946e0a458390105eb"
1575 integrity sha512-L1ibTdA5IUe/cRBlf3N3syAOBQSN1WCMGtAWir6mKxibiRl4LmpZM4jLz+7zAqiMnhQuAP1sqZOF9wXgn2kpEg== 1582 integrity sha512-L1ibTdA5IUe/cRBlf3N3syAOBQSN1WCMGtAWir6mKxibiRl4LmpZM4jLz+7zAqiMnhQuAP1sqZOF9wXgn2kpEg==
@@ -7376,6 +7383,11 @@ map-visit@^1.0.0:
7376 dependencies: 7383 dependencies:
7377 object-visit "^1.0.0" 7384 object-visit "^1.0.0"
7378 7385
7386markdown-it-emoji@^1.4.0:
7387 version "1.4.0"
7388 resolved "https://registry.yarnpkg.com/markdown-it-emoji/-/markdown-it-emoji-1.4.0.tgz#9bee0e9a990a963ba96df6980c4fddb05dfb4dcc"
7389 integrity sha1-m+4OmpkKljupbfaYDE/dsF37Tcw=
7390
7379markdown-it@^11.0.0: 7391markdown-it@^11.0.0:
7380 version "11.0.0" 7392 version "11.0.0"
7381 resolved "https://registry.yarnpkg.com/markdown-it/-/markdown-it-11.0.0.tgz#dbfc30363e43d756ebc52c38586b91b90046b876" 7393 resolved "https://registry.yarnpkg.com/markdown-it/-/markdown-it-11.0.0.tgz#dbfc30363e43d756ebc52c38586b91b90046b876"
diff --git a/package.json b/package.json
index 4e4e58878..02c456e82 100644
--- a/package.json
+++ b/package.json
@@ -202,6 +202,7 @@
202 "eslint-plugin-standard": "^4.0.1", 202 "eslint-plugin-standard": "^4.0.1",
203 "libxmljs": "0.19.7", 203 "libxmljs": "0.19.7",
204 "maildev": "^1.0.0-rc3", 204 "maildev": "^1.0.0-rc3",
205 "markdown-it-emoji": "^1.4.0",
205 "marked": "^1.1.0", 206 "marked": "^1.1.0",
206 "marked-man": "^0.7.0", 207 "marked-man": "^0.7.0",
207 "mocha": "^8.0.1", 208 "mocha": "^8.0.1",
@@ -219,7 +220,7 @@
219 "_moduleAliases": { 220 "_moduleAliases": {
220 "@server": "dist/server" 221 "@server": "dist/server"
221 }, 222 },
222 "bundlewatch" : { 223 "bundlewatch": {
223 "files": [ 224 "files": [
224 { 225 {
225 "path": "client/dist/en-US/*-es2015.js", 226 "path": "client/dist/en-US/*-es2015.js",
diff --git a/yarn.lock b/yarn.lock
index 01d16b986..7714244d2 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -4774,6 +4774,11 @@ make-plural@^6.2.1:
4774 resolved "https://registry.yarnpkg.com/make-plural/-/make-plural-6.2.1.tgz#2790af1d05fb2fc35a111ce759ffdb0aca1339a3" 4774 resolved "https://registry.yarnpkg.com/make-plural/-/make-plural-6.2.1.tgz#2790af1d05fb2fc35a111ce759ffdb0aca1339a3"
4775 integrity sha512-AmkruwJ9EjvyTv6AM8MBMK3TAeOJvhgTv5YQXzF0EP2qawhpvMjDpHvsdOIIT0Vn+BB0+IogmYZ1z+Ulm/m0Fg== 4775 integrity sha512-AmkruwJ9EjvyTv6AM8MBMK3TAeOJvhgTv5YQXzF0EP2qawhpvMjDpHvsdOIIT0Vn+BB0+IogmYZ1z+Ulm/m0Fg==
4776 4776
4777markdown-it-emoji@^1.4.0:
4778 version "1.4.0"
4779 resolved "https://registry.yarnpkg.com/markdown-it-emoji/-/markdown-it-emoji-1.4.0.tgz#9bee0e9a990a963ba96df6980c4fddb05dfb4dcc"
4780 integrity sha1-m+4OmpkKljupbfaYDE/dsF37Tcw=
4781
4777marked-man@^0.7.0: 4782marked-man@^0.7.0:
4778 version "0.7.0" 4783 version "0.7.0"
4779 resolved "https://registry.yarnpkg.com/marked-man/-/marked-man-0.7.0.tgz#220ba01d275d16f1a98e4e7fc3c5eac0630c68e4" 4784 resolved "https://registry.yarnpkg.com/marked-man/-/marked-man-0.7.0.tgz#220ba01d275d16f1a98e4e7fc3c5eac0630c68e4"