fix(md): fix some markdown rendering issues (#2862)

* fix(md): correctly append feedback on linked headings

* fix(md): make sure to use vitepress' default link renderer
This commit is contained in:
rhld16 2025-01-19 15:56:09 +00:00 committed by GitHub
parent 6d6b4abe9f
commit 9fd6157ec9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -40,7 +40,7 @@ export const headersPlugin = (md: MarkdownRenderer) => {
// //
// The token after `heading_open` contains the link as a child token. // The token after `heading_open` contains the link as a child token.
const children = tokens[idx + 1].children || [] const children = tokens[idx + 1].children || []
const linkOpenToken = children.find((c) => c.type === 'link_open') const linkOpenToken = children.findLast((c) => c.type === 'link_open')
if (!linkOpenToken) return result if (!linkOpenToken) return result
const heading = tokens[idxClose - 1] const heading = tokens[idxClose - 1]
@ -53,8 +53,10 @@ export const headersPlugin = (md: MarkdownRenderer) => {
return result return result
} }
let defaultRender = md.renderer.rules.link_open;
md.renderer.rules.link_open = (tokens, idx, options, env, self) => { md.renderer.rules.link_open = (tokens, idx, options, env, self) => {
const result = self.renderToken(tokens, idx, options) const result = defaultRender(tokens, idx, options, env, self);
const meta = tokens[idx].meta const meta = tokens[idx].meta
if (!meta || !meta.feedback) return result if (!meta || !meta.feedback) return result