diff options
Diffstat (limited to 'client/src/app/core/renderer')
-rw-r--r-- | client/src/app/core/renderer/markdown.service.ts | 21 |
1 files changed, 13 insertions, 8 deletions
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 @@ | |||
1 | import * as MarkdownIt from 'markdown-it' | 1 | import * as MarkdownIt from 'markdown-it' |
2 | import MarkdownItEmoji from 'markdown-it-emoji' | ||
2 | import { buildVideoLink } from 'src/assets/player/utils' | 3 | import { buildVideoLink } from 'src/assets/player/utils' |
3 | import { Injectable } from '@angular/core' | 4 | import { Injectable } from '@angular/core' |
4 | import { HtmlRendererService } from './html-renderer.service' | 5 | import { 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) |