aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/renderer
diff options
context:
space:
mode:
authorLesterpig <git@lesterpig.com>2019-10-02 21:17:10 +0200
committerChocobozzz <chocobozzz@cpy.re>2019-12-17 09:45:02 +0100
commitd68ebf0b4a40f88e53a78de6b3109a41466fa7c6 (patch)
treebbe02b16b88351b354c99f959c888d36444e719c /client/src/app/shared/renderer
parenta0dedc02ca870a31298eb35d5105a1ebc34dbb4a (diff)
downloadPeerTube-d68ebf0b4a40f88e53a78de6b3109a41466fa7c6.tar.gz
PeerTube-d68ebf0b4a40f88e53a78de6b3109a41466fa7c6.tar.zst
PeerTube-d68ebf0b4a40f88e53a78de6b3109a41466fa7c6.zip
Add hyperlink video timestamps in description
Fix #1312 (duplicates: #1728 and #2007) The modification is also applied to comments and video editing.
Diffstat (limited to 'client/src/app/shared/renderer')
-rw-r--r--client/src/app/shared/renderer/markdown.service.ts11
1 files changed, 10 insertions, 1 deletions
diff --git a/client/src/app/shared/renderer/markdown.service.ts b/client/src/app/shared/renderer/markdown.service.ts
index 629bbb140..f6b71b88a 100644
--- a/client/src/app/shared/renderer/markdown.service.ts
+++ b/client/src/app/shared/renderer/markdown.service.ts
@@ -1,5 +1,6 @@
1import { Injectable } from '@angular/core' 1import { Injectable } from '@angular/core'
2import { MarkdownIt } from 'markdown-it' 2import { MarkdownIt } from 'markdown-it'
3import { buildVideoLink } from '../../../assets/player/utils'
3import { HtmlRendererService } from '@app/shared/renderer/html-renderer.service' 4import { HtmlRendererService } from '@app/shared/renderer/html-renderer.service'
4 5
5type MarkdownParsers = { 6type MarkdownParsers = {
@@ -90,6 +91,14 @@ export class MarkdownService {
90 return html 91 return html
91 } 92 }
92 93
94 async processVideoTimestamps (html: string) {
95 return html.replace(/((\d{1,2}):)?(\d{1,2}):(\d{1,2})/g, function (str, _, h, m, s) {
96 const t = (3600 * +(h || 0)) + (60 * +(m || 0)) + (+(s || 0))
97 const url = buildVideoLink({ startTime: t })
98 return `<a href="${url}">${str}</a>`
99 })
100 }
101
93 private async createMarkdownIt (config: MarkdownConfig) { 102 private async createMarkdownIt (config: MarkdownConfig) {
94 // FIXME: import('...') returns a struct module, containing a "default" field corresponding to our sanitizeHtml function 103 // FIXME: import('...') returns a struct module, containing a "default" field corresponding to our sanitizeHtml function
95 const MarkdownItClass: typeof import ('markdown-it') = (await import('markdown-it') as any).default 104 const MarkdownItClass: typeof import ('markdown-it') = (await import('markdown-it') as any).default
@@ -130,7 +139,7 @@ export class MarkdownService {
130 private avoidTruncatedTags (html: string) { 139 private avoidTruncatedTags (html: string) {
131 return html.replace(/\*\*?([^*]+)$/, '$1') 140 return html.replace(/\*\*?([^*]+)$/, '$1')
132 .replace(/<a[^>]+>([^<]+)<\/a>\s*...((<\/p>)|(<\/li>)|(<\/strong>))?$/mi, '$1...') 141 .replace(/<a[^>]+>([^<]+)<\/a>\s*...((<\/p>)|(<\/li>)|(<\/strong>))?$/mi, '$1...')
133 .replace(/\[[^\]]+\]\(([^\)]+)$/m, '$1') 142 .replace(/\[[^\]]+\]?\(?([^\)]+)$/, '$1')
134 .replace(/\s?\[[^\]]+\]?[.]{3}<\/p>$/m, '...</p>') 143 .replace(/\s?\[[^\]]+\]?[.]{3}<\/p>$/m, '...</p>')
135 } 144 }
136} 145}