]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - 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
1506307f 1import { Injectable } from '@angular/core'
67ed6552 2import { LinkifierService } from './linkifier.service'
9ff36c2d 3import { SANITIZE_OPTIONS } from '@shared/core-utils/renderer/html'
1506307f
C
4
5@Injectable()
6export class HtmlRendererService {
d573926e 7 private sanitizeHtml: typeof import ('sanitize-html')
1506307f
C
8
9 constructor (private linkifier: LinkifierService) {
10
11 }
12
d573926e
C
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
41d71344 23 async toSafeHtml (text: string) {
d573926e 24 await this.loadSanitizeHtml()
41d71344 25
1506307f
C
26 // Convert possible markdown to html
27 const html = this.linkifier.linkify(text)
28
9ff36c2d 29 return this.sanitizeHtml(html, SANITIZE_OPTIONS)
1506307f 30 }
d573926e
C
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 }
1506307f 36}