import { Injectable } from '@angular/core'
+import { getCustomMarkupSanitizeOptions, getDefaultSanitizeOptions } from '@shared/core-utils/renderer/html'
import { LinkifierService } from './linkifier.service'
-import { SANITIZE_OPTIONS } from '@shared/core-utils/renderer/html'
@Injectable()
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),
+
+ this.loadSanitizeHtml()
+ ])
- // Convert possible markdown to html
- const html = this.linkifier.linkify(text)
+ const options = additionalAllowedTags.length !== 0
+ ? getCustomMarkupSanitizeOptions(additionalAllowedTags)
+ : getDefaultSanitizeOptions()
- return this.sanitizeHtml(html, SANITIZE_OPTIONS)
+ return this.sanitizeHtml(html, options)
}
private async loadSanitizeHtml () {