diff options
author | Chocobozzz <me@florianbigard.com> | 2018-02-20 11:04:21 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-02-20 11:04:21 +0100 |
commit | 3d9eaae318670986fedab257b8be344c9b43d8d5 (patch) | |
tree | 6aaa8ff8d5fd7d162e05147eb02f3175ab8c933c /client/src/app/videos/shared | |
parent | 5de8a55abce53108bc1024f1194457c6528bd11e (diff) | |
download | PeerTube-3d9eaae318670986fedab257b8be344c9b43d8d5.tar.gz PeerTube-3d9eaae318670986fedab257b8be344c9b43d8d5.tar.zst PeerTube-3d9eaae318670986fedab257b8be344c9b43d8d5.zip |
Add links support in comments
Diffstat (limited to 'client/src/app/videos/shared')
-rw-r--r-- | client/src/app/videos/shared/markdown.service.ts | 16 |
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() |
6 | export class MarkdownService { | 6 | export 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 | ||