aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/core/renderer
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-07-28 09:57:16 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-07-31 11:35:19 +0200
commitd573926e9b94fb19c8f51c53f71fc853182e1761 (patch)
tree907cc81c7275efe30aa90047c0763a7254bd1063 /client/src/app/core/renderer
parent594d3e48d8a887bbf48ce4cc594c1c36c9640fb1 (diff)
downloadPeerTube-d573926e9b94fb19c8f51c53f71fc853182e1761.tar.gz
PeerTube-d573926e9b94fb19c8f51c53f71fc853182e1761.tar.zst
PeerTube-d573926e9b94fb19c8f51c53f71fc853182e1761.zip
Add migrations for abuse messages
Diffstat (limited to 'client/src/app/core/renderer')
-rw-r--r--client/src/app/core/renderer/html-renderer.service.ts21
1 files changed, 18 insertions, 3 deletions
diff --git a/client/src/app/core/renderer/html-renderer.service.ts b/client/src/app/core/renderer/html-renderer.service.ts
index f0527c759..302d92ed9 100644
--- a/client/src/app/core/renderer/html-renderer.service.ts
+++ b/client/src/app/core/renderer/html-renderer.service.ts
@@ -3,19 +3,29 @@ import { LinkifierService } from './linkifier.service'
3 3
4@Injectable() 4@Injectable()
5export class HtmlRendererService { 5export class HtmlRendererService {
6 private sanitizeHtml: typeof import ('sanitize-html')
6 7
7 constructor (private linkifier: LinkifierService) { 8 constructor (private linkifier: LinkifierService) {
8 9
9 } 10 }
10 11
12 async convertToBr (text: string) {
13 await this.loadSanitizeHtml()
14
15 const html = text.replace(/\r?\n/g, '<br />')
16
17 return this.sanitizeHtml(html, {
18 allowedTags: [ 'br' ]
19 })
20 }
21
11 async toSafeHtml (text: string) { 22 async toSafeHtml (text: string) {
12 // FIXME: import('..') returns a struct module, containing a "default" field corresponding to our sanitizeHtml function 23 await this.loadSanitizeHtml()
13 const sanitizeHtml: typeof import ('sanitize-html') = (await import('sanitize-html') as any).default
14 24
15 // Convert possible markdown to html 25 // Convert possible markdown to html
16 const html = this.linkifier.linkify(text) 26 const html = this.linkifier.linkify(text)
17 27
18 return sanitizeHtml(html, { 28 return this.sanitizeHtml(html, {
19 allowedTags: [ 'a', 'p', 'span', 'br', 'strong', 'em', 'ul', 'ol', 'li' ], 29 allowedTags: [ 'a', 'p', 'span', 'br', 'strong', 'em', 'ul', 'ol', 'li' ],
20 allowedSchemes: [ 'http', 'https' ], 30 allowedSchemes: [ 'http', 'https' ],
21 allowedAttributes: { 31 allowedAttributes: {
@@ -37,4 +47,9 @@ export class HtmlRendererService {
37 } 47 }
38 }) 48 })
39 } 49 }
50
51 private async loadSanitizeHtml () {
52 // FIXME: import('..') returns a struct module, containing a "default" field corresponding to our sanitizeHtml function
53 this.sanitizeHtml = (await import('sanitize-html') as any).default
54 }
40} 55}