refactor: reuse original markdown-it renderer rule (#932)

pull/934/head
meteorlxy 2 years ago committed by GitHub
parent 973dbe4eec
commit e7960f4b6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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)
}
}

Loading…
Cancel
Save