From d158ac3529f810f65cc2a13f52ce90734438ed20 Mon Sep 17 00:00:00 2001 From: dengyongchi Date: Fri, 26 Jan 2024 17:58:59 +0800 Subject: [PATCH] feat: handle `` tag in the markdown file --- src/node/markdown/plugins/image.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/node/markdown/plugins/image.ts b/src/node/markdown/plugins/image.ts index d6f7eb5f..0bcd9d51 100644 --- a/src/node/markdown/plugins/image.ts +++ b/src/node/markdown/plugins/image.ts @@ -25,4 +25,21 @@ export const imagePlugin = (md: MarkdownIt, { lazyLoading }: Options = {}) => { } return imageRule(tokens, idx, options, env, self) } + if (lazyLoading) { + // handle `` tag in the markdown file + const regex = /]*)\/>/gi + const replacement = '' + const htmlInlineRule = md.renderer.rules.html_inline! + md.renderer.rules.html_inline = (tokens, idx, options, env, self) => { + const token = tokens[idx]! + token.content = token.content.replace(regex, replacement) + return htmlInlineRule(tokens, idx, options, env, self) + } + const htmlBlockRule = md.renderer.rules.html_block! + md.renderer.rules.html_block = (tokens, idx, options, env, self) => { + const token = tokens[idx]! + token.content = token.content.replace(regex, replacement) + return htmlBlockRule(tokens, idx, options, env, self) + } + } }