diff options
author | Chocobozzz <me@florianbigard.com> | 2018-02-20 10:41:11 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-02-20 10:41:11 +0100 |
commit | 5de8a55abce53108bc1024f1194457c6528bd11e (patch) | |
tree | 24d55c349807581a86872490753c2e1bddff932d /client | |
parent | 2f315e2f915514eaddee30394b0d99790bcda06b (diff) | |
download | PeerTube-5de8a55abce53108bc1024f1194457c6528bd11e.tar.gz PeerTube-5de8a55abce53108bc1024f1194457c6528bd11e.tar.zst PeerTube-5de8a55abce53108bc1024f1194457c6528bd11e.zip |
Handle line feeds in comments
Diffstat (limited to 'client')
3 files changed, 14 insertions, 4 deletions
diff --git a/client/src/app/shared/misc/utils.ts b/client/src/app/shared/misc/utils.ts index e2e4c5b36..64bc69b0d 100644 --- a/client/src/app/shared/misc/utils.ts +++ b/client/src/app/shared/misc/utils.ts | |||
@@ -88,6 +88,12 @@ function objectToFormData (obj: any, form?: FormData, namespace?: string) { | |||
88 | return fd | 88 | return fd |
89 | } | 89 | } |
90 | 90 | ||
91 | function lineFeedToHtml (obj: object, keyToNormalize: string) { | ||
92 | return immutableAssign(obj, { | ||
93 | [keyToNormalize]: obj[keyToNormalize].replace(/\r?\n|\r/g, '<br />') | ||
94 | }) | ||
95 | } | ||
96 | |||
91 | export { | 97 | export { |
92 | viewportHeight, | 98 | viewportHeight, |
93 | getParameterByName, | 99 | getParameterByName, |
@@ -97,5 +103,6 @@ export { | |||
97 | isInSmallView, | 103 | isInSmallView, |
98 | isInMobileView, | 104 | isInMobileView, |
99 | immutableAssign, | 105 | immutableAssign, |
100 | objectToFormData | 106 | objectToFormData, |
107 | lineFeedToHtml | ||
101 | } | 108 | } |
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 7c664ca60..9176de80f 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 | |||
@@ -90,7 +90,7 @@ export class VideoCommentComponent implements OnInit, OnChanges { | |||
90 | 90 | ||
91 | private init () { | 91 | private init () { |
92 | this.sanitizedCommentHTML = sanitizeHtml(this.comment.text, { | 92 | this.sanitizedCommentHTML = sanitizeHtml(this.comment.text, { |
93 | allowedTags: [ 'p', 'span' ] | 93 | allowedTags: [ 'p', 'span', 'br' ] |
94 | }) | 94 | }) |
95 | 95 | ||
96 | this.newParentComments = this.parentComments.concat([ this.comment ]) | 96 | this.newParentComments = this.parentComments.concat([ this.comment ]) |
diff --git a/client/src/app/videos/+video-watch/comment/video-comment.service.ts b/client/src/app/videos/+video-watch/comment/video-comment.service.ts index c42f55496..14d32b1aa 100644 --- a/client/src/app/videos/+video-watch/comment/video-comment.service.ts +++ b/client/src/app/videos/+video-watch/comment/video-comment.service.ts | |||
@@ -2,6 +2,7 @@ import { HttpClient, HttpParams } from '@angular/common/http' | |||
2 | import { Injectable } from '@angular/core' | 2 | import { Injectable } from '@angular/core' |
3 | import 'rxjs/add/operator/catch' | 3 | import 'rxjs/add/operator/catch' |
4 | import 'rxjs/add/operator/map' | 4 | import 'rxjs/add/operator/map' |
5 | import { immutableAssign, lineFeedToHtml } from '@app/shared/misc/utils' | ||
5 | import { Observable } from 'rxjs/Observable' | 6 | import { Observable } from 'rxjs/Observable' |
6 | import { ResultList } from '../../../../../../shared/models' | 7 | import { ResultList } from '../../../../../../shared/models' |
7 | import { | 8 | import { |
@@ -26,16 +27,18 @@ export class VideoCommentService { | |||
26 | 27 | ||
27 | addCommentThread (videoId: number | string, comment: VideoCommentCreate) { | 28 | addCommentThread (videoId: number | string, comment: VideoCommentCreate) { |
28 | const url = VideoCommentService.BASE_VIDEO_URL + videoId + '/comment-threads' | 29 | const url = VideoCommentService.BASE_VIDEO_URL + videoId + '/comment-threads' |
30 | const normalizedComment = lineFeedToHtml(comment, 'text') | ||
29 | 31 | ||
30 | return this.authHttp.post(url, comment) | 32 | return this.authHttp.post(url, normalizedComment) |
31 | .map(data => this.extractVideoComment(data['comment'])) | 33 | .map(data => this.extractVideoComment(data['comment'])) |
32 | .catch(this.restExtractor.handleError) | 34 | .catch(this.restExtractor.handleError) |
33 | } | 35 | } |
34 | 36 | ||
35 | addCommentReply (videoId: number | string, inReplyToCommentId: number, comment: VideoCommentCreate) { | 37 | addCommentReply (videoId: number | string, inReplyToCommentId: number, comment: VideoCommentCreate) { |
36 | const url = VideoCommentService.BASE_VIDEO_URL + videoId + '/comments/' + inReplyToCommentId | 38 | const url = VideoCommentService.BASE_VIDEO_URL + videoId + '/comments/' + inReplyToCommentId |
39 | const normalizedComment = lineFeedToHtml(comment, 'text') | ||
37 | 40 | ||
38 | return this.authHttp.post(url, comment) | 41 | return this.authHttp.post(url, normalizedComment) |
39 | .map(data => this.extractVideoComment(data['comment'])) | 42 | .map(data => this.extractVideoComment(data['comment'])) |
40 | .catch(this.restExtractor.handleError) | 43 | .catch(this.restExtractor.handleError) |
41 | } | 44 | } |