]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - client/src/app/core/renderer/html-renderer.service.ts
Use sass instead of deprecated node sass
[github/Chocobozzz/PeerTube.git] / client / src / app / core / renderer / html-renderer.service.ts
... / ...
CommitLineData
1import { Injectable } from '@angular/core'
2import { LinkifierService } from './linkifier.service'
3import { SANITIZE_OPTIONS } from '@shared/core-utils/renderer/html'
4
5@Injectable()
6export class HtmlRendererService {
7 private sanitizeHtml: typeof import ('sanitize-html')
8
9 constructor (private linkifier: LinkifierService) {
10
11 }
12
13 async convertToBr (text: string) {
14 await this.loadSanitizeHtml()
15
16 const html = text.replace(/\r?\n/g, '<br />')
17
18 return this.sanitizeHtml(html, {
19 allowedTags: [ 'br' ]
20 })
21 }
22
23 async toSafeHtml (text: string) {
24 await this.loadSanitizeHtml()
25
26 // Convert possible markdown to html
27 const html = this.linkifier.linkify(text)
28
29 return this.sanitizeHtml(html, SANITIZE_OPTIONS)
30 }
31
32 private async loadSanitizeHtml () {
33 // FIXME: import('..') returns a struct module, containing a "default" field corresponding to our sanitizeHtml function
34 this.sanitizeHtml = (await import('sanitize-html') as any).default
35 }
36}