aboutsummaryrefslogtreecommitdiffhomepage
path: root/client
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 /client
parent438c256b2672fa9539b703e6f28d4b70ef3dccfb (diff)
downloadPeerTube-0672dc769b6ee42b4357748c62aaeabf8801c472.tar.gz
PeerTube-0672dc769b6ee42b4357748c62aaeabf8801c472.tar.zst
PeerTube-0672dc769b6ee42b4357748c62aaeabf8801c472.zip
Add unicode emoji to markdown
Diffstat (limited to 'client')
-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
5 files changed, 29 insertions, 10 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"