diff options
author | Chocobozzz <me@florianbigard.com> | 2018-02-21 16:44:18 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-02-21 16:44:43 +0100 |
commit | e8cb44090e654fda339506dccfcec7fea8722723 (patch) | |
tree | 2a36d264cf44cededff0e272919316a3feabcbc1 /client/src/app/videos/+video-watch/comment/video-comment.component.ts | |
parent | 276d03ed1a469fd4e3579f92392b6f9a1567d1ca (diff) | |
download | PeerTube-e8cb44090e654fda339506dccfcec7fea8722723.tar.gz PeerTube-e8cb44090e654fda339506dccfcec7fea8722723.tar.zst PeerTube-e8cb44090e654fda339506dccfcec7fea8722723.zip |
Add links to comment mentions
Diffstat (limited to 'client/src/app/videos/+video-watch/comment/video-comment.component.ts')
-rw-r--r-- | client/src/app/videos/+video-watch/comment/video-comment.component.ts | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/client/src/app/videos/+video-watch/comment/video-comment.component.ts b/client/src/app/videos/+video-watch/comment/video-comment.component.ts index 0224132ac..8f2d79ec1 100644 --- a/client/src/app/videos/+video-watch/comment/video-comment.component.ts +++ b/client/src/app/videos/+video-watch/comment/video-comment.component.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { Component, EventEmitter, Input, OnChanges, OnInit, Output } from '@angular/core' | 1 | import { Component, EventEmitter, Input, OnChanges, OnInit, Output } from '@angular/core' |
2 | import { MarkdownService } from '@app/videos/shared' | 2 | import { LinkifierService } from '@app/videos/+video-watch/comment/linkifier.service' |
3 | import * as sanitizeHtml from 'sanitize-html' | 3 | import * as sanitizeHtml from 'sanitize-html' |
4 | import { Account as AccountInterface } from '../../../../../../shared/models/actors' | 4 | import { Account as AccountInterface } from '../../../../../../shared/models/actors' |
5 | import { UserRight } from '../../../../../../shared/models/users' | 5 | import { UserRight } from '../../../../../../shared/models/users' |
@@ -31,8 +31,8 @@ export class VideoCommentComponent implements OnInit, OnChanges { | |||
31 | newParentComments = [] | 31 | newParentComments = [] |
32 | 32 | ||
33 | constructor ( | 33 | constructor ( |
34 | private authService: AuthService, | 34 | private linkifierService: LinkifierService, |
35 | private markdownService: MarkdownService | 35 | private authService: AuthService |
36 | ) {} | 36 | ) {} |
37 | 37 | ||
38 | get user () { | 38 | get user () { |
@@ -93,14 +93,27 @@ export class VideoCommentComponent implements OnInit, OnChanges { | |||
93 | } | 93 | } |
94 | 94 | ||
95 | private init () { | 95 | private init () { |
96 | this.sanitizedCommentHTML = sanitizeHtml(this.comment.text, { | 96 | // Convert possible markdown to html |
97 | const html = this.linkifierService.linkify(this.comment.text) | ||
98 | |||
99 | this.sanitizedCommentHTML = sanitizeHtml(html, { | ||
97 | allowedTags: [ 'a', 'p', 'span', 'br' ], | 100 | allowedTags: [ 'a', 'p', 'span', 'br' ], |
98 | allowedSchemes: [ 'http', 'https' ] | 101 | allowedSchemes: [ 'http', 'https' ], |
102 | allowedAttributes: { | ||
103 | 'a': [ 'href', 'class' ] | ||
104 | }, | ||
105 | transformTags: { | ||
106 | a: (tagName, attribs) => { | ||
107 | return { | ||
108 | tagName, | ||
109 | attribs: Object.assign(attribs, { | ||
110 | target: '_blank' | ||
111 | }) | ||
112 | } | ||
113 | } | ||
114 | } | ||
99 | }) | 115 | }) |
100 | 116 | ||
101 | // Convert possible markdown to html | ||
102 | this.sanitizedCommentHTML = this.markdownService.linkify(this.comment.text) | ||
103 | |||
104 | this.newParentComments = this.parentComments.concat([ this.comment ]) | 117 | this.newParentComments = this.parentComments.concat([ this.comment ]) |
105 | } | 118 | } |
106 | } | 119 | } |