aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/core/renderer/html-renderer.service.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-11-17 14:34:09 +0100
committerChocobozzz <me@florianbigard.com>2020-11-17 14:34:09 +0100
commit9ff36c2d70956d2775d207c7809adb6fe7f2f2a5 (patch)
treec9058f8210d9674b69307c4f7c5ccde85a1ba597 /client/src/app/core/renderer/html-renderer.service.ts
parent9afb5c10e5935e667e33219bdbd775e9ed1b4330 (diff)
downloadPeerTube-9ff36c2d70956d2775d207c7809adb6fe7f2f2a5.tar.gz
PeerTube-9ff36c2d70956d2775d207c7809adb6fe7f2f2a5.tar.zst
PeerTube-9ff36c2d70956d2775d207c7809adb6fe7f2f2a5.zip
Refactor markdown/sanitize html code
Diffstat (limited to 'client/src/app/core/renderer/html-renderer.service.ts')
-rw-r--r--client/src/app/core/renderer/html-renderer.service.ts23
1 files changed, 2 insertions, 21 deletions
diff --git a/client/src/app/core/renderer/html-renderer.service.ts b/client/src/app/core/renderer/html-renderer.service.ts
index 302d92ed9..1fe91b96b 100644
--- a/client/src/app/core/renderer/html-renderer.service.ts
+++ b/client/src/app/core/renderer/html-renderer.service.ts
@@ -1,5 +1,6 @@
1import { Injectable } from '@angular/core' 1import { Injectable } from '@angular/core'
2import { LinkifierService } from './linkifier.service' 2import { LinkifierService } from './linkifier.service'
3import { SANITIZE_OPTIONS } from '@shared/core-utils/renderer/html'
3 4
4@Injectable() 5@Injectable()
5export class HtmlRendererService { 6export class HtmlRendererService {
@@ -25,27 +26,7 @@ export class HtmlRendererService {
25 // Convert possible markdown to html 26 // Convert possible markdown to html
26 const html = this.linkifier.linkify(text) 27 const html = this.linkifier.linkify(text)
27 28
28 return this.sanitizeHtml(html, { 29 return this.sanitizeHtml(html, SANITIZE_OPTIONS)
29 allowedTags: [ 'a', 'p', 'span', 'br', 'strong', 'em', 'ul', 'ol', 'li' ],
30 allowedSchemes: [ 'http', 'https' ],
31 allowedAttributes: {
32 'a': [ 'href', 'class', 'target', 'rel' ]
33 },
34 transformTags: {
35 a: (tagName, attribs) => {
36 let rel = 'noopener noreferrer'
37 if (attribs.rel === 'me') rel += ' me'
38
39 return {
40 tagName,
41 attribs: Object.assign(attribs, {
42 target: '_blank',
43 rel
44 })
45 }
46 }
47 }
48 })
49 } 30 }
50 31
51 private async loadSanitizeHtml () { 32 private async loadSanitizeHtml () {