1 import { Injectable } from '@angular/core'
2 import { LinkifierService } from '@app/shared/renderer/linkifier.service'
5 export class HtmlRendererService {
7 constructor (private linkifier: LinkifierService) {
11 async toSafeHtml (text: string) {
12 // FIXME: import('..') returns a struct module, containing a "default" field corresponding to our sanitizeHtml function
13 const sanitizeHtml: typeof import ('sanitize-html') = (await import('sanitize-html') as any).default
15 // Convert possible markdown to html
16 const html = this.linkifier.linkify(text)
18 return sanitizeHtml(html, {
19 allowedTags: [ 'a', 'p', 'span', 'br' ],
20 allowedSchemes: [ 'http', 'https' ],
22 'a': [ 'href', 'class', 'target' ]
25 a: (tagName, attribs) => {
28 attribs: Object.assign(attribs, {
30 rel: 'noopener noreferrer'