diff options
Diffstat (limited to 'client/src/app/videos/shared')
-rw-r--r-- | client/src/app/videos/shared/markdown.service.ts | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/client/src/app/videos/shared/markdown.service.ts b/client/src/app/videos/shared/markdown.service.ts index 82745f0c6..fd0330f9b 100644 --- a/client/src/app/videos/shared/markdown.service.ts +++ b/client/src/app/videos/shared/markdown.service.ts | |||
@@ -14,6 +14,17 @@ export class MarkdownService { | |||
14 | .enable('link') | 14 | .enable('link') |
15 | .enable('newline') | 15 | .enable('newline') |
16 | 16 | ||
17 | this.setTargetToLinks() | ||
18 | } | ||
19 | |||
20 | markdownToHTML (markdown: string) { | ||
21 | const html = this.markdownIt.render(markdown) | ||
22 | |||
23 | // Avoid linkify truncated links | ||
24 | return html.replace(/<a[^>]+>([^<]+)<\/a>\s*...(<\/p>)?$/mi, '$1...') | ||
25 | } | ||
26 | |||
27 | private setTargetToLinks () { | ||
17 | // Snippet from markdown-it documentation: https://github.com/markdown-it/markdown-it/blob/master/docs/architecture.md#renderer | 28 | // Snippet from markdown-it documentation: https://github.com/markdown-it/markdown-it/blob/master/docs/architecture.md#renderer |
18 | const defaultRender = this.markdownIt.renderer.rules.link_open || function (tokens, idx, options, env, self) { | 29 | const defaultRender = this.markdownIt.renderer.rules.link_open || function (tokens, idx, options, env, self) { |
19 | return self.renderToken(tokens, idx, options) | 30 | return self.renderToken(tokens, idx, options) |
@@ -33,11 +44,4 @@ export class MarkdownService { | |||
33 | return defaultRender(tokens, idx, options, env, self) | 44 | return defaultRender(tokens, idx, options, env, self) |
34 | } | 45 | } |
35 | } | 46 | } |
36 | |||
37 | markdownToHTML (markdown: string) { | ||
38 | const html = this.markdownIt.render(markdown) | ||
39 | |||
40 | // Avoid linkify truncated links | ||
41 | return html.replace(/<a[^>]+>([^<]+)<\/a>\s*...(<\/p>)?$/mi, '$1...') | ||
42 | } | ||
43 | } | 47 | } |