diff options
author | Chocobozzz <me@florianbigard.com> | 2019-12-06 14:01:28 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-12-06 14:01:28 +0100 |
commit | 3131c13e0208eb3a33dec1a1f0d21727c820a50d (patch) | |
tree | de6abeaf2cecac25ffe4f236f0f40cf8614cf465 /client/src/app/shared/renderer | |
parent | 7e049ea4673f05cbb90b37199bb93713cc0d5611 (diff) | |
download | PeerTube-3131c13e0208eb3a33dec1a1f0d21727c820a50d.tar.gz PeerTube-3131c13e0208eb3a33dec1a1f0d21727c820a50d.tar.zst PeerTube-3131c13e0208eb3a33dec1a1f0d21727c820a50d.zip |
Don't support images in account descriptions
Diffstat (limited to 'client/src/app/shared/renderer')
-rw-r--r-- | client/src/app/shared/renderer/markdown.service.ts | 29 |
1 files changed, 20 insertions, 9 deletions
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 | ||