X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fcore%2Frenderer%2Fhtml-renderer.service.ts;h=302d92ed961a7e2da2a4439947f535b888353fc6;hb=d573926e9b94fb19c8f51c53f71fc853182e1761;hp=f0527c759355312477af13bcae6e4e3ad77771f8;hpb=594d3e48d8a887bbf48ce4cc594c1c36c9640fb1;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/core/renderer/html-renderer.service.ts b/client/src/app/core/renderer/html-renderer.service.ts index f0527c759..302d92ed9 100644 --- a/client/src/app/core/renderer/html-renderer.service.ts +++ b/client/src/app/core/renderer/html-renderer.service.ts @@ -3,19 +3,29 @@ import { LinkifierService } from './linkifier.service' @Injectable() export class HtmlRendererService { + private sanitizeHtml: typeof import ('sanitize-html') constructor (private linkifier: LinkifierService) { } + async convertToBr (text: string) { + await this.loadSanitizeHtml() + + const html = text.replace(/\r?\n/g, '
') + + return this.sanitizeHtml(html, { + allowedTags: [ 'br' ] + }) + } + async toSafeHtml (text: string) { - // FIXME: import('..') returns a struct module, containing a "default" field corresponding to our sanitizeHtml function - const sanitizeHtml: typeof import ('sanitize-html') = (await import('sanitize-html') as any).default + await this.loadSanitizeHtml() // Convert possible markdown to html const html = this.linkifier.linkify(text) - return sanitizeHtml(html, { + return this.sanitizeHtml(html, { allowedTags: [ 'a', 'p', 'span', 'br', 'strong', 'em', 'ul', 'ol', 'li' ], allowedSchemes: [ 'http', 'https' ], allowedAttributes: { @@ -37,4 +47,9 @@ export class HtmlRendererService { } }) } + + private async loadSanitizeHtml () { + // FIXME: import('..') returns a struct module, containing a "default" field corresponding to our sanitizeHtml function + this.sanitizeHtml = (await import('sanitize-html') as any).default + } }