From d68ebf0b4a40f88e53a78de6b3109a41466fa7c6 Mon Sep 17 00:00:00 2001 From: Lesterpig Date: Wed, 2 Oct 2019 21:17:10 +0200 Subject: Add hyperlink video timestamps in description Fix #1312 (duplicates: #1728 and #2007) The modification is also applied to comments and video editing. --- client/src/app/shared/renderer/markdown.service.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'client/src/app/shared/renderer') 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 @@ import { Injectable } from '@angular/core' import { MarkdownIt } from 'markdown-it' +import { buildVideoLink } from '../../../assets/player/utils' import { HtmlRendererService } from '@app/shared/renderer/html-renderer.service' type MarkdownParsers = { @@ -90,6 +91,14 @@ export class MarkdownService { return html } + async processVideoTimestamps (html: string) { + return html.replace(/((\d{1,2}):)?(\d{1,2}):(\d{1,2})/g, function (str, _, h, m, s) { + const t = (3600 * +(h || 0)) + (60 * +(m || 0)) + (+(s || 0)) + const url = buildVideoLink({ startTime: t }) + return `${str}` + }) + } + private async createMarkdownIt (config: MarkdownConfig) { // FIXME: import('...') returns a struct module, containing a "default" field corresponding to our sanitizeHtml function const MarkdownItClass: typeof import ('markdown-it') = (await import('markdown-it') as any).default @@ -130,7 +139,7 @@ export class MarkdownService { private avoidTruncatedTags (html: string) { return html.replace(/\*\*?([^*]+)$/, '$1') .replace(/]+>([^<]+)<\/a>\s*...((<\/p>)|(<\/li>)|(<\/strong>))?$/mi, '$1...') - .replace(/\[[^\]]+\]\(([^\)]+)$/m, '$1') + .replace(/\[[^\]]+\]?\(?([^\)]+)$/, '$1') .replace(/\s?\[[^\]]+\]?[.]{3}<\/p>$/m, '...

') } } -- cgit v1.2.3