From 369e77543b0e2cd24f2353dcf6a715fca350556c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 19 Nov 2020 16:26:32 +0100 Subject: Lazy load emoji --- client/src/app/core/renderer/markdown.service.ts | 10 +++++++--- client/src/typings.d.ts | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'client') diff --git a/client/src/app/core/renderer/markdown.service.ts b/client/src/app/core/renderer/markdown.service.ts index 0fde3f99d..edddb0a66 100644 --- a/client/src/app/core/renderer/markdown.service.ts +++ b/client/src/app/core/renderer/markdown.service.ts @@ -49,6 +49,8 @@ export class MarkdownService { completeMarkdownIt: { rules: COMPLETE_RULES, html: true } } + private emojiModule: any + constructor (private htmlRenderer: HtmlRendererService) {} textMarkdownToHTML (markdown: string, withHtml = false, withEmoji = false) { @@ -83,9 +85,11 @@ export class MarkdownService { this.markdownParsers[ name ] = await this.createMarkdownIt(config) if (withEmoji) { - // TODO: write types - const emoji = require('markdown-it-emoji/light') - this.markdownParsers[ name ].use(emoji) + if (!this.emojiModule) { + this.emojiModule = (await import('markdown-it-emoji/light')).default + } + + this.markdownParsers[ name ].use(this.emojiModule) } } diff --git a/client/src/typings.d.ts b/client/src/typings.d.ts index ef6c9f2f5..24473aede 100644 --- a/client/src/typings.d.ts +++ b/client/src/typings.d.ts @@ -4,3 +4,5 @@ declare var module: NodeModule interface NodeModule { id: string } + +declare module 'markdown-it-emoji/light' -- cgit v1.2.3