]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/renderer/html-renderer.service.ts
Fix displaying more dropdown on touchscreen
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / renderer / html-renderer.service.ts
CommitLineData
1506307f
C
1import { Injectable } from '@angular/core'
2import { LinkifierService } from '@app/shared/renderer/linkifier.service'
1506307f
C
3
4@Injectable()
5export class HtmlRendererService {
6
7 constructor (private linkifier: LinkifierService) {
8
9 }
10
41d71344
C
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
14
1506307f
C
15 // Convert possible markdown to html
16 const html = this.linkifier.linkify(text)
17
18 return sanitizeHtml(html, {
1aa75434 19 allowedTags: [ 'a', 'p', 'span', 'br', 'strong', 'em', 'ul', 'ol', 'li' ],
1506307f
C
20 allowedSchemes: [ 'http', 'https' ],
21 allowedAttributes: {
891bc2ff 22 'a': [ 'href', 'class', 'target', 'rel' ]
1506307f
C
23 },
24 transformTags: {
25 a: (tagName, attribs) => {
891bc2ff
C
26 let rel = 'noopener noreferrer'
27 if (attribs.rel === 'me') rel += ' me'
28
1506307f
C
29 return {
30 tagName,
31 attribs: Object.assign(attribs, {
32 target: '_blank',
891bc2ff 33 rel
1506307f
C
34 })
35 }
36 }
37 }
38 })
39 }
40}