Add unicode emoji to markdown
This commit is contained in:
parent
438c256b26
commit
0672dc769b
|
@ -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",
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
<li>Links</li>
|
||||
<li>Break lines</li>
|
||||
<li>Lists</li>
|
||||
<li>Emojis</li>
|
||||
</ul>
|
||||
</div>
|
||||
</ng-template>
|
||||
|
|
|
@ -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 ])
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -1569,7 +1569,14 @@
|
|||
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"
|
||||
|
|
|
@ -202,6 +202,7 @@
|
|||
"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",
|
||||
|
@ -219,7 +220,7 @@
|
|||
"_moduleAliases": {
|
||||
"@server": "dist/server"
|
||||
},
|
||||
"bundlewatch" : {
|
||||
"bundlewatch": {
|
||||
"files": [
|
||||
{
|
||||
"path": "client/dist/en-US/*-es2015.js",
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue