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