import { FormBuilder, FormGroup } from '@angular/forms'
import { NotificationsService } from 'angular2-notifications'
import { Observable } from 'rxjs/Observable'
-import { VideoCommentCreate, VideoCommentThreadTree } from '../../../../../../shared/models/videos/video-comment.model'
+import { VideoCommentCreate } from '../../../../../../shared/models/videos/video-comment.model'
import { FormReactive } from '../../../shared'
import { VIDEO_COMMENT_TEXT } from '../../../shared/forms/form-validators/video-comment'
import { User } from '../../../shared/users'
import { Component, EventEmitter, Input, OnChanges, OnInit, Output } from '@angular/core'
+import { MarkdownService } from '@app/videos/shared'
import * as sanitizeHtml from 'sanitize-html'
import { Account as AccountInterface } from '../../../../../../shared/models/actors'
import { UserRight } from '../../../../../../shared/models/users'
sanitizedCommentHTML = ''
newParentComments = []
- constructor (private authService: AuthService) {}
+ constructor (
+ private authService: AuthService,
+ private markdownService: MarkdownService
+ ) {}
get user () {
return this.authService.getUser()
private init () {
this.sanitizedCommentHTML = sanitizeHtml(this.comment.text, {
- allowedTags: [ 'p', 'span', 'br' ]
+ allowedTags: [ 'a', 'p', 'span', 'br' ],
+ allowedSchemes: [ 'http', 'https' ]
})
+ // Convert possible markdown to html
+ this.sanitizedCommentHTML = this.markdownService.linkify(this.comment.text)
+
this.newParentComments = this.parentComments.concat([ this.comment ])
}
}
import { HttpClient, HttpParams } from '@angular/common/http'
import { Injectable } from '@angular/core'
+import { lineFeedToHtml } from '@app/shared/misc/utils'
+import { MarkdownService } from '@app/videos/shared'
import 'rxjs/add/operator/catch'
import 'rxjs/add/operator/map'
-import { immutableAssign, lineFeedToHtml } from '@app/shared/misc/utils'
import { Observable } from 'rxjs/Observable'
import { ResultList } from '../../../../../../shared/models'
import {
- VideoComment as VideoCommentServerModel, VideoCommentCreate,
+ VideoComment as VideoCommentServerModel,
+ VideoCommentCreate,
VideoCommentThreadTree
} from '../../../../../../shared/models/videos/video-comment.model'
import { environment } from '../../../../environments/environment'
@Injectable()
export class MarkdownService {
private markdownIt: MarkdownIt.MarkdownIt
+ private linkifier: MarkdownIt.MarkdownIt
constructor () {
this.markdownIt = new MarkdownIt('zero', { linkify: true, breaks: true })
.enable('link')
.enable('newline')
.enable('list')
+ this.setTargetToLinks(this.markdownIt)
- this.setTargetToLinks()
+ this.linkifier = new MarkdownIt('zero', { linkify: true })
+ .enable('linkify')
+ this.setTargetToLinks(this.linkifier)
}
markdownToHTML (markdown: string) {
return html.replace(/<a[^>]+>([^<]+)<\/a>\s*...(<\/p>)?$/mi, '$1...')
}
- private setTargetToLinks () {
+ linkify (text: string) {
+ return this.linkifier.render(text)
+ }
+
+ private setTargetToLinks (markdownIt: MarkdownIt.MarkdownIt) {
// Snippet from markdown-it documentation: https://github.com/markdown-it/markdown-it/blob/master/docs/architecture.md#renderer
- const defaultRender = this.markdownIt.renderer.rules.link_open || function (tokens, idx, options, env, self) {
+ const defaultRender = markdownIt.renderer.rules.link_open || function (tokens, idx, options, env, self) {
return self.renderToken(tokens, idx, options)
}
- this.markdownIt.renderer.rules.link_open = function (tokens, idx, options, env, self) {
+ markdownIt.renderer.rules.link_open = function (tokens, idx, options, env, self) {
// If you are sure other plugins can't add `target` - drop check below
const aIndex = tokens[idx].attrIndex('target')