1 import { Injectable } from '@angular/core'
2 import { LinkifierService } from './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', 'strong', 'em', 'ul', 'ol', 'li' ],
20 allowedSchemes: [ 'http', 'https' ],
22 'a': [ 'href', 'class', 'target', 'rel' ]
25 a: (tagName, attribs) => {
26 let rel = 'noopener noreferrer'
27 if (attribs.rel === 'me') rel += ' me'
31 attribs: Object.assign(attribs, {