From 1eb23e12f757dc4e9a6161b1b933f35a761755c3 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 5 Sep 2019 15:39:52 +0200 Subject: Add contributors in about peertube page --- client/src/app/shared/renderer/markdown.service.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'client/src/app/shared') diff --git a/client/src/app/shared/renderer/markdown.service.ts b/client/src/app/shared/renderer/markdown.service.ts index 9a9066351..0e24f3085 100644 --- a/client/src/app/shared/renderer/markdown.service.ts +++ b/client/src/app/shared/renderer/markdown.service.ts @@ -13,9 +13,11 @@ export class MarkdownService { 'list' ] static ENHANCED_RULES = MarkdownService.TEXT_RULES.concat([ 'image' ]) + static COMPLETE_RULES = MarkdownService.ENHANCED_RULES.concat([ 'block', 'inline', 'heading', 'html_inline', 'html_block', 'paragraph' ]) private textMarkdownIt: MarkdownIt private enhancedMarkdownIt: MarkdownIt + private completeMarkdownIt: MarkdownIt async textMarkdownToHTML (markdown: string) { if (!markdown) return '' @@ -39,11 +41,22 @@ export class MarkdownService { return this.avoidTruncatedTags(html) } - private async createMarkdownIt (rules: string[]) { - // FIXME: import('..') returns a struct module, containing a "default" field corresponding to our sanitizeHtml function + async completeMarkdownToHTML (markdown: string) { + if (!markdown) return '' + + if (!this.completeMarkdownIt) { + this.completeMarkdownIt = await this.createMarkdownIt(MarkdownService.COMPLETE_RULES, true) + } + + const html = this.completeMarkdownIt.render(markdown) + return this.avoidTruncatedTags(html) + } + + private async createMarkdownIt (rules: string[], html = false) { + // 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 - const markdownIt = new MarkdownItClass('zero', { linkify: true, breaks: true }) + const markdownIt = new MarkdownItClass('zero', { linkify: true, breaks: true, html }) for (const rule of rules) { markdownIt.enable(rule) -- cgit v1.2.3