diff options
-rw-r--r-- | client/src/app/+accounts/account-about/account-about.component.ts | 2 | ||||
-rw-r--r-- | client/src/app/shared/renderer/markdown.service.ts | 29 |
2 files changed, 21 insertions, 10 deletions
diff --git a/client/src/app/+accounts/account-about/account-about.component.ts b/client/src/app/+accounts/account-about/account-about.component.ts index c65bad3f2..d1616490f 100644 --- a/client/src/app/+accounts/account-about/account-about.component.ts +++ b/client/src/app/+accounts/account-about/account-about.component.ts | |||
@@ -27,7 +27,7 @@ export class AccountAboutComponent implements OnInit, OnDestroy { | |||
27 | this.accountSub = this.accountService.accountLoaded | 27 | this.accountSub = this.accountService.accountLoaded |
28 | .subscribe(async account => { | 28 | .subscribe(async account => { |
29 | this.account = account | 29 | this.account = account |
30 | this.descriptionHTML = await this.markdownService.enhancedMarkdownToHTML(this.account.description, true) | 30 | this.descriptionHTML = await this.markdownService.textMarkdownToHTML(this.account.description, true) |
31 | }) | 31 | }) |
32 | } | 32 | } |
33 | 33 | ||
diff --git a/client/src/app/shared/renderer/markdown.service.ts b/client/src/app/shared/renderer/markdown.service.ts index 09bbbfb7e..fc1f18c2b 100644 --- a/client/src/app/shared/renderer/markdown.service.ts +++ b/client/src/app/shared/renderer/markdown.service.ts | |||
@@ -1,12 +1,14 @@ | |||
1 | import { Injectable } from '@angular/core' | 1 | import { Injectable } from '@angular/core' |
2 | import { MarkdownIt } from 'markdown-it' | 2 | import { MarkdownIt } from 'markdown-it' |
3 | import { HtmlRendererService } from '@app/shared/renderer/html-renderer.service' | 3 | import { HtmlRendererService } from '@app/shared/renderer/html-renderer.service' |
4 | import { mark } from '@angular/compiler-cli/src/ngtsc/perf/src/clock' | ||
5 | 4 | ||
6 | type MarkdownParsers = { | 5 | type MarkdownParsers = { |
7 | textMarkdownIt: MarkdownIt | 6 | textMarkdownIt: MarkdownIt |
7 | textWithHTMLMarkdownIt: MarkdownIt | ||
8 | |||
8 | enhancedMarkdownIt: MarkdownIt | 9 | enhancedMarkdownIt: MarkdownIt |
9 | enhancedMarkdownWithHTMLIt: MarkdownIt | 10 | enhancedWithHTMLMarkdownIt: MarkdownIt |
11 | |||
10 | completeMarkdownIt: MarkdownIt | 12 | completeMarkdownIt: MarkdownIt |
11 | } | 13 | } |
12 | 14 | ||
@@ -30,36 +32,45 @@ export class MarkdownService { | |||
30 | 'newline', | 32 | 'newline', |
31 | 'list' | 33 | 'list' |
32 | ] | 34 | ] |
35 | static TEXT_WITH_HTML_RULES = MarkdownService.TEXT_RULES.concat([ 'html_inline', 'html_block' ]) | ||
36 | |||
33 | static ENHANCED_RULES = MarkdownService.TEXT_RULES.concat([ 'image' ]) | 37 | static ENHANCED_RULES = MarkdownService.TEXT_RULES.concat([ 'image' ]) |
34 | static ENHANCED_WITH_HTML_RULES = MarkdownService.ENHANCED_RULES.concat([ 'html_inline', 'html_block' ]) | 38 | static ENHANCED_WITH_HTML_RULES = MarkdownService.TEXT_WITH_HTML_RULES.concat([ 'image' ]) |
39 | |||
35 | static COMPLETE_RULES = MarkdownService.ENHANCED_WITH_HTML_RULES.concat([ 'block', 'inline', 'heading', 'paragraph' ]) | 40 | static COMPLETE_RULES = MarkdownService.ENHANCED_WITH_HTML_RULES.concat([ 'block', 'inline', 'heading', 'paragraph' ]) |
36 | 41 | ||
37 | private markdownParsers: MarkdownParsers = { | 42 | private markdownParsers: MarkdownParsers = { |
38 | textMarkdownIt: null, | 43 | textMarkdownIt: null, |
44 | textWithHTMLMarkdownIt: null, | ||
39 | enhancedMarkdownIt: null, | 45 | enhancedMarkdownIt: null, |
40 | enhancedMarkdownWithHTMLIt: null, | 46 | enhancedWithHTMLMarkdownIt: null, |
41 | completeMarkdownIt: null | 47 | completeMarkdownIt: null |
42 | } | 48 | } |
43 | private parsersConfig: MarkdownParserConfigs = { | 49 | private parsersConfig: MarkdownParserConfigs = { |
44 | textMarkdownIt: { rules: MarkdownService.TEXT_RULES, html: false }, | 50 | textMarkdownIt: { rules: MarkdownService.TEXT_RULES, html: false }, |
51 | textWithHTMLMarkdownIt: { rules: MarkdownService.TEXT_WITH_HTML_RULES, html: true, escape: true }, | ||
52 | |||
45 | enhancedMarkdownIt: { rules: MarkdownService.ENHANCED_RULES, html: false }, | 53 | enhancedMarkdownIt: { rules: MarkdownService.ENHANCED_RULES, html: false }, |
46 | enhancedMarkdownWithHTMLIt: { rules: MarkdownService.ENHANCED_WITH_HTML_RULES, html: true, escape: true }, | 54 | enhancedWithHTMLMarkdownIt: { rules: MarkdownService.ENHANCED_WITH_HTML_RULES, html: true, escape: true }, |
55 | |||
47 | completeMarkdownIt: { rules: MarkdownService.COMPLETE_RULES, html: true } | 56 | completeMarkdownIt: { rules: MarkdownService.COMPLETE_RULES, html: true } |
48 | } | 57 | } |
49 | 58 | ||
50 | constructor (private htmlRenderer: HtmlRendererService) {} | 59 | constructor (private htmlRenderer: HtmlRendererService) {} |
51 | 60 | ||
52 | textMarkdownToHTML (markdown: string) { | 61 | textMarkdownToHTML (markdown: string, withHtml = false) { |
62 | if (withHtml) return this.render('textWithHTMLMarkdownIt', markdown) | ||
63 | |||
53 | return this.render('textMarkdownIt', markdown) | 64 | return this.render('textMarkdownIt', markdown) |
54 | } | 65 | } |
55 | 66 | ||
56 | async enhancedMarkdownToHTML (markdown: string, withHtml = false) { | 67 | enhancedMarkdownToHTML (markdown: string, withHtml = false) { |
57 | if (withHtml) return this.render('enhancedMarkdownWithHTMLIt', markdown) | 68 | if (withHtml) return this.render('enhancedWithHTMLMarkdownIt', markdown) |
58 | 69 | ||
59 | return this.render('enhancedMarkdownIt', markdown) | 70 | return this.render('enhancedMarkdownIt', markdown) |
60 | } | 71 | } |
61 | 72 | ||
62 | async completeMarkdownToHTML (markdown: string) { | 73 | completeMarkdownToHTML (markdown: string) { |
63 | return this.render('completeMarkdownIt', markdown) | 74 | return this.render('completeMarkdownIt', markdown) |
64 | } | 75 | } |
65 | 76 | ||