From 94898e40459a8b8680ba00002de04f9661893cf5 Mon Sep 17 00:00:00 2001 From: meteorlxy Date: Fri, 8 Jul 2022 02:13:56 +0800 Subject: [PATCH] refactor: reuse original markdown-it renderer rule --- src/node/markdown/plugins/image.ts | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/node/markdown/plugins/image.ts b/src/node/markdown/plugins/image.ts index 59dadcc1..c61eadf8 100644 --- a/src/node/markdown/plugins/image.ts +++ b/src/node/markdown/plugins/image.ts @@ -4,21 +4,13 @@ import MarkdownIt from 'markdown-it' import { EXTERNAL_URL_RE } from '../../shared' export const imagePlugin = (md: MarkdownIt) => { + const imageRule = md.renderer.rules.image! md.renderer.rules.image = (tokens, idx, options, env, self) => { const token = tokens[idx] const url = token.attrGet('src') if (url && !EXTERNAL_URL_RE.test(url) && !/^\.?\//.test(url)) { token.attrSet('src', './' + url) } - - if (token.attrIndex('alt') && token.children != null) { - token.attrs![token.attrIndex('alt')][1] = self.renderInlineAsText( - token.children, - options, - env - ) - } - - return self.renderToken(tokens, idx, options) + return imageRule(tokens, idx, options, env, self) } }