aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/videos/shared
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/videos/shared')
-rw-r--r--client/src/app/videos/shared/markdown.service.ts16
1 files changed, 12 insertions, 4 deletions
diff --git a/client/src/app/videos/shared/markdown.service.ts b/client/src/app/videos/shared/markdown.service.ts
index 3f51a82ce..a275446eb 100644
--- a/client/src/app/videos/shared/markdown.service.ts
+++ b/client/src/app/videos/shared/markdown.service.ts
@@ -5,6 +5,7 @@ import * as MarkdownIt from 'markdown-it'
5@Injectable() 5@Injectable()
6export class MarkdownService { 6export class MarkdownService {
7 private markdownIt: MarkdownIt.MarkdownIt 7 private markdownIt: MarkdownIt.MarkdownIt
8 private linkifier: MarkdownIt.MarkdownIt
8 9
9 constructor () { 10 constructor () {
10 this.markdownIt = new MarkdownIt('zero', { linkify: true, breaks: true }) 11 this.markdownIt = new MarkdownIt('zero', { linkify: true, breaks: true })
@@ -14,8 +15,11 @@ export class MarkdownService {
14 .enable('link') 15 .enable('link')
15 .enable('newline') 16 .enable('newline')
16 .enable('list') 17 .enable('list')
18 this.setTargetToLinks(this.markdownIt)
17 19
18 this.setTargetToLinks() 20 this.linkifier = new MarkdownIt('zero', { linkify: true })
21 .enable('linkify')
22 this.setTargetToLinks(this.linkifier)
19 } 23 }
20 24
21 markdownToHTML (markdown: string) { 25 markdownToHTML (markdown: string) {
@@ -25,13 +29,17 @@ export class MarkdownService {
25 return html.replace(/<a[^>]+>([^<]+)<\/a>\s*...(<\/p>)?$/mi, '$1...') 29 return html.replace(/<a[^>]+>([^<]+)<\/a>\s*...(<\/p>)?$/mi, '$1...')
26 } 30 }
27 31
28 private setTargetToLinks () { 32 linkify (text: string) {
33 return this.linkifier.render(text)
34 }
35
36 private setTargetToLinks (markdownIt: MarkdownIt.MarkdownIt) {
29 // Snippet from markdown-it documentation: https://github.com/markdown-it/markdown-it/blob/master/docs/architecture.md#renderer 37 // Snippet from markdown-it documentation: https://github.com/markdown-it/markdown-it/blob/master/docs/architecture.md#renderer
30 const defaultRender = this.markdownIt.renderer.rules.link_open || function (tokens, idx, options, env, self) { 38 const defaultRender = markdownIt.renderer.rules.link_open || function (tokens, idx, options, env, self) {
31 return self.renderToken(tokens, idx, options) 39 return self.renderToken(tokens, idx, options)
32 } 40 }
33 41
34 this.markdownIt.renderer.rules.link_open = function (tokens, idx, options, env, self) { 42 markdownIt.renderer.rules.link_open = function (tokens, idx, options, env, self) {
35 // If you are sure other plugins can't add `target` - drop check below 43 // If you are sure other plugins can't add `target` - drop check below
36 const aIndex = tokens[idx].attrIndex('target') 44 const aIndex = tokens[idx].attrIndex('target')
37 45