aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/shared')
-rw-r--r--client/src/app/shared/renderer/markdown.service.ts19
1 files changed, 16 insertions, 3 deletions
diff --git a/client/src/app/shared/renderer/markdown.service.ts b/client/src/app/shared/renderer/markdown.service.ts
index 9a9066351..0e24f3085 100644
--- a/client/src/app/shared/renderer/markdown.service.ts
+++ b/client/src/app/shared/renderer/markdown.service.ts
@@ -13,9 +13,11 @@ export class MarkdownService {
13 'list' 13 'list'
14 ] 14 ]
15 static ENHANCED_RULES = MarkdownService.TEXT_RULES.concat([ 'image' ]) 15 static ENHANCED_RULES = MarkdownService.TEXT_RULES.concat([ 'image' ])
16 static COMPLETE_RULES = MarkdownService.ENHANCED_RULES.concat([ 'block', 'inline', 'heading', 'html_inline', 'html_block', 'paragraph' ])
16 17
17 private textMarkdownIt: MarkdownIt 18 private textMarkdownIt: MarkdownIt
18 private enhancedMarkdownIt: MarkdownIt 19 private enhancedMarkdownIt: MarkdownIt
20 private completeMarkdownIt: MarkdownIt
19 21
20 async textMarkdownToHTML (markdown: string) { 22 async textMarkdownToHTML (markdown: string) {
21 if (!markdown) return '' 23 if (!markdown) return ''
@@ -39,11 +41,22 @@ export class MarkdownService {
39 return this.avoidTruncatedTags(html) 41 return this.avoidTruncatedTags(html)
40 } 42 }
41 43
42 private async createMarkdownIt (rules: string[]) { 44 async completeMarkdownToHTML (markdown: string) {
43 // FIXME: import('..') returns a struct module, containing a "default" field corresponding to our sanitizeHtml function 45 if (!markdown) return ''
46
47 if (!this.completeMarkdownIt) {
48 this.completeMarkdownIt = await this.createMarkdownIt(MarkdownService.COMPLETE_RULES, true)
49 }
50
51 const html = this.completeMarkdownIt.render(markdown)
52 return this.avoidTruncatedTags(html)
53 }
54
55 private async createMarkdownIt (rules: string[], html = false) {
56 // FIXME: import('...') returns a struct module, containing a "default" field corresponding to our sanitizeHtml function
44 const MarkdownItClass: typeof import ('markdown-it') = (await import('markdown-it') as any).default 57 const MarkdownItClass: typeof import ('markdown-it') = (await import('markdown-it') as any).default
45 58
46 const markdownIt = new MarkdownItClass('zero', { linkify: true, breaks: true }) 59 const markdownIt = new MarkdownItClass('zero', { linkify: true, breaks: true, html })
47 60
48 for (const rule of rules) { 61 for (const rule of rules) {
49 markdownIt.enable(rule) 62 markdownIt.enable(rule)