diff options
Diffstat (limited to 'client/src/app/shared/renderer/markdown.service.ts')
-rw-r--r-- | client/src/app/shared/renderer/markdown.service.ts | 11 |
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 @@ | |||
1 | import { Injectable } from '@angular/core' | 1 | import { Injectable } from '@angular/core' |
2 | import { MarkdownIt } from 'markdown-it' | 2 | import { MarkdownIt } from 'markdown-it' |
3 | import { buildVideoLink } from '../../../assets/player/utils' | ||
3 | import { HtmlRendererService } from '@app/shared/renderer/html-renderer.service' | 4 | import { HtmlRendererService } from '@app/shared/renderer/html-renderer.service' |
4 | 5 | ||
5 | type MarkdownParsers = { | 6 | type 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 | } |