]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/renderer/html-renderer.service.ts
Merge branch 'develop' into pr/1217
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / renderer / html-renderer.service.ts
1 import { Injectable } from '@angular/core'
2 import { LinkifierService } from '@app/shared/renderer/linkifier.service'
3 import * as sanitizeHtml from 'sanitize-html'
4
5 @Injectable()
6 export class HtmlRendererService {
7
8 constructor (private linkifier: LinkifierService) {
9
10 }
11
12 toSafeHtml (text: string) {
13 // Convert possible markdown to html
14 const html = this.linkifier.linkify(text)
15
16 return sanitizeHtml(html, {
17 allowedTags: [ 'a', 'p', 'span', 'br' ],
18 allowedSchemes: [ 'http', 'https' ],
19 allowedAttributes: {
20 'a': [ 'href', 'class', 'target' ]
21 },
22 transformTags: {
23 a: (tagName, attribs) => {
24 return {
25 tagName,
26 attribs: Object.assign(attribs, {
27 target: '_blank',
28 rel: 'noopener noreferrer'
29 })
30 }
31 }
32 }
33 })
34 }
35 }