aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/videos/shared
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-02-20 16:13:05 +0100
committerChocobozzz <me@florianbigard.com>2018-02-20 16:13:55 +0100
commit07fa4c97ca50b83b0bee9230da97d02401b4e05f (patch)
tree07a5ef1b14d8f0596c241456e4cc772f38c0e4ba /client/src/app/videos/shared
parentdddf58c8ce58f6cdd4b8ba93690cceae8f52c37d (diff)
downloadPeerTube-07fa4c97ca50b83b0bee9230da97d02401b4e05f.tar.gz
PeerTube-07fa4c97ca50b83b0bee9230da97d02401b4e05f.tar.zst
PeerTube-07fa4c97ca50b83b0bee9230da97d02401b4e05f.zip
Add support to video support on client
Diffstat (limited to 'client/src/app/videos/shared')
-rw-r--r--client/src/app/videos/shared/markdown.service.ts38
1 files changed, 30 insertions, 8 deletions
diff --git a/client/src/app/videos/shared/markdown.service.ts b/client/src/app/videos/shared/markdown.service.ts
index a275446eb..bd100f092 100644
--- a/client/src/app/videos/shared/markdown.service.ts
+++ b/client/src/app/videos/shared/markdown.service.ts
@@ -4,33 +4,51 @@ import * as MarkdownIt from 'markdown-it'
4 4
5@Injectable() 5@Injectable()
6export class MarkdownService { 6export class MarkdownService {
7 private markdownIt: MarkdownIt.MarkdownIt 7 private textMarkdownIt: MarkdownIt.MarkdownIt
8 private linkifier: MarkdownIt.MarkdownIt 8 private linkifier: MarkdownIt.MarkdownIt
9 private enhancedMarkdownIt: MarkdownIt.MarkdownIt
9 10
10 constructor () { 11 constructor () {
11 this.markdownIt = new MarkdownIt('zero', { linkify: true, breaks: true }) 12 this.textMarkdownIt = new MarkdownIt('zero', { linkify: true, breaks: true })
12 .enable('linkify') 13 .enable('linkify')
13 .enable('autolink') 14 .enable('autolink')
14 .enable('emphasis') 15 .enable('emphasis')
15 .enable('link') 16 .enable('link')
16 .enable('newline') 17 .enable('newline')
17 .enable('list') 18 .enable('list')
18 this.setTargetToLinks(this.markdownIt) 19 this.setTargetToLinks(this.textMarkdownIt)
20
21 this.enhancedMarkdownIt = new MarkdownIt('zero', { linkify: true, breaks: true })
22 .enable('linkify')
23 .enable('autolink')
24 .enable('emphasis')
25 .enable('link')
26 .enable('newline')
27 .enable('list')
28 .enable('image')
29 this.setTargetToLinks(this.enhancedMarkdownIt)
19 30
20 this.linkifier = new MarkdownIt('zero', { linkify: true }) 31 this.linkifier = new MarkdownIt('zero', { linkify: true })
21 .enable('linkify') 32 .enable('linkify')
22 this.setTargetToLinks(this.linkifier) 33 this.setTargetToLinks(this.linkifier)
23 } 34 }
24 35
25 markdownToHTML (markdown: string) { 36 textMarkdownToHTML (markdown: string) {
26 const html = this.markdownIt.render(markdown) 37 const html = this.textMarkdownIt.render(markdown)
27 38
28 // Avoid linkify truncated links 39 return this.avoidTruncatedLinks(html)
29 return html.replace(/<a[^>]+>([^<]+)<\/a>\s*...(<\/p>)?$/mi, '$1...') 40 }
41
42 enhancedMarkdownToHTML (markdown: string) {
43 const html = this.enhancedMarkdownIt.render(markdown)
44
45 return this.avoidTruncatedLinks(html)
30 } 46 }
31 47
32 linkify (text: string) { 48 linkify (text: string) {
33 return this.linkifier.render(text) 49 const html = this.linkifier.render(text)
50
51 return this.avoidTruncatedLinks(html)
34 } 52 }
35 53
36 private setTargetToLinks (markdownIt: MarkdownIt.MarkdownIt) { 54 private setTargetToLinks (markdownIt: MarkdownIt.MarkdownIt) {
@@ -53,4 +71,8 @@ export class MarkdownService {
53 return defaultRender(tokens, idx, options, env, self) 71 return defaultRender(tokens, idx, options, env, self)
54 } 72 }
55 } 73 }
74
75 private avoidTruncatedLinks (html) {
76 return html.replace(/<a[^>]+>([^<]+)<\/a>\s*...(<\/p>)?$/mi, '$1...')
77 }
56} 78}