From 0672dc769b6ee42b4357748c62aaeabf8801c472 Mon Sep 17 00:00:00 2001 From: kimsible Date: Sat, 8 Aug 2020 12:01:28 +0200 Subject: Add unicode emoji to markdown --- .../comment/video-comment-add.component.html | 1 + .../+video-watch/comment/video-comment.component.ts | 2 +- client/src/app/core/renderer/markdown.service.ts | 21 +++++++++++++-------- 3 files changed, 15 insertions(+), 9 deletions(-) (limited to 'client/src/app') diff --git a/client/src/app/+videos/+video-watch/comment/video-comment-add.component.html b/client/src/app/+videos/+video-watch/comment/video-comment-add.component.html index ec8da02e2..b4f8bda5e 100644 --- a/client/src/app/+videos/+video-watch/comment/video-comment-add.component.html +++ b/client/src/app/+videos/+video-watch/comment/video-comment-add.component.html @@ -13,6 +13,7 @@
  • Links
  • Break lines
  • Lists
  • +
  • Emojis
  • 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 fe069b54c..5491023ee 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 @@ -149,7 +149,7 @@ export class VideoCommentComponent implements OnInit, OnChanges { } private async init () { - const html = await this.markdownService.textMarkdownToHTML(this.comment.text, true) + const html = await this.markdownService.textMarkdownToHTML(this.comment.text, true, true) this.sanitizedCommentHTML = await this.markdownService.processVideoTimestamps(html) this.newParentComments = this.parentComments.concat([ this.comment ]) diff --git a/client/src/app/core/renderer/markdown.service.ts b/client/src/app/core/renderer/markdown.service.ts index 0c43bebab..2ff3de34e 100644 --- a/client/src/app/core/renderer/markdown.service.ts +++ b/client/src/app/core/renderer/markdown.service.ts @@ -1,4 +1,5 @@ import * as MarkdownIt from 'markdown-it' +import MarkdownItEmoji from 'markdown-it-emoji' import { buildVideoLink } from 'src/assets/player/utils' import { Injectable } from '@angular/core' import { HtmlRendererService } from './html-renderer.service' @@ -59,20 +60,20 @@ export class MarkdownService { constructor (private htmlRenderer: HtmlRendererService) {} - textMarkdownToHTML (markdown: string, withHtml = false) { - if (withHtml) return this.render('textWithHTMLMarkdownIt', markdown) + textMarkdownToHTML (markdown: string, withHtml = false, withEmoji = false) { + if (withHtml) return this.render('textWithHTMLMarkdownIt', markdown, withEmoji) - return this.render('textMarkdownIt', markdown) + return this.render('textMarkdownIt', markdown, withEmoji) } - enhancedMarkdownToHTML (markdown: string, withHtml = false) { - if (withHtml) return this.render('enhancedWithHTMLMarkdownIt', markdown) + enhancedMarkdownToHTML (markdown: string, withHtml = false, withEmoji = false) { + if (withHtml) return this.render('enhancedWithHTMLMarkdownIt', markdown, withEmoji) - return this.render('enhancedMarkdownIt', markdown) + return this.render('enhancedMarkdownIt', markdown, withEmoji) } completeMarkdownToHTML (markdown: string) { - return this.render('completeMarkdownIt', markdown) + return this.render('completeMarkdownIt', markdown, true) } async processVideoTimestamps (html: string) { @@ -83,12 +84,16 @@ export class MarkdownService { }) } - private async render (name: keyof MarkdownParsers, markdown: string) { + private async render (name: keyof MarkdownParsers, markdown: string, withEmoji = false) { if (!markdown) return '' const config = this.parsersConfig[ name ] if (!this.markdownParsers[ name ]) { this.markdownParsers[ name ] = await this.createMarkdownIt(config) + + if (withEmoji) { + this.markdownParsers[ name ].use(MarkdownItEmoji) + } } let html = this.markdownParsers[ name ].render(markdown) -- cgit v1.2.3