X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fcore%2Frenderer%2Fhtml-renderer.service.ts;h=d158519f8f973f07749b288c9f55c37e8dd7c0d8;hb=0e45e336f62a411b3c423be46d16252355c754d7;hp=302d92ed961a7e2da2a4439947f535b888353fc6;hpb=d573926e9b94fb19c8f51c53f71fc853182e1761;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 302d92ed9..d158519f8 100644 --- a/client/src/app/core/renderer/html-renderer.service.ts +++ b/client/src/app/core/renderer/html-renderer.service.ts @@ -1,4 +1,5 @@ import { Injectable } from '@angular/core' +import { getCustomMarkupSanitizeOptions, getDefaultSanitizeOptions } from '@shared/core-utils/renderer/html' import { LinkifierService } from './linkifier.service' @Injectable() @@ -19,33 +20,19 @@ export class HtmlRendererService { }) } - async toSafeHtml (text: string) { - await this.loadSanitizeHtml() + async toSafeHtml (text: string, additionalAllowedTags: string[] = []) { + const [ html ] = await Promise.all([ + // Convert possible markdown to html + this.linkifier.linkify(text), - // Convert possible markdown to html - const html = this.linkifier.linkify(text) + this.loadSanitizeHtml() + ]) - return this.sanitizeHtml(html, { - allowedTags: [ 'a', 'p', 'span', 'br', 'strong', 'em', 'ul', 'ol', 'li' ], - allowedSchemes: [ 'http', 'https' ], - allowedAttributes: { - 'a': [ 'href', 'class', 'target', 'rel' ] - }, - transformTags: { - a: (tagName, attribs) => { - let rel = 'noopener noreferrer' - if (attribs.rel === 'me') rel += ' me' - - return { - tagName, - attribs: Object.assign(attribs, { - target: '_blank', - rel - }) - } - } - } - }) + const options = additionalAllowedTags.length !== 0 + ? getCustomMarkupSanitizeOptions(additionalAllowedTags) + : getDefaultSanitizeOptions() + + return this.sanitizeHtml(html, options) } private async loadSanitizeHtml () {