fix(plugin-md-power): incorrect rending of footnote in annotation (#686)

This commit is contained in:
pengzhanbo 2025-09-03 23:41:04 +08:00 committed by GitHub
parent 46b2da25a6
commit 2c39edf849
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 9 deletions

View File

@ -4,6 +4,7 @@ import type { RuleInline } from 'markdown-it/lib/parser_inline.mjs'
import type StateBlock from 'markdown-it/lib/rules_block/state_block.mjs'
import type StateInline from 'markdown-it/lib/rules_inline/state_inline.mjs'
import type Token from 'markdown-it/lib/token.mjs'
import { cleanMarkdownEnv } from '../utils/cleanMarkdownEnv'
interface AnnotationToken extends Token {
meta: {
@ -165,7 +166,7 @@ export const annotationPlugin: PluginSimple = (md) => {
return `<Annotation label="${label}" :total="${data.sources.length}">${
data.sources.map((source, i) => {
const annotation = data.rendered[i] ??= md.render(source, env)
const annotation = data.rendered[i] ??= md.render(source, cleanMarkdownEnv(env, ['references']))
return `<template #item-${i}>${annotation}</template>`
}).join('')
}</Annotation>`

View File

@ -6,13 +6,16 @@ export interface CleanMarkdownEnv extends MarkdownEnv {
annotations?: unknown
}
export function cleanMarkdownEnv(env: CleanMarkdownEnv): CleanMarkdownEnv {
return {
base: env.base,
filePath: env.filePath,
filePathRelative: env.filePathRelative,
references: env.references,
abbreviations: env.abbreviations,
annotations: env.annotations,
const WHITE_LIST = ['base', 'filePath', 'filePathRelative', 'references', 'abbreviations', 'annotations'] as const
type WhiteListUnion = (typeof WHITE_LIST)[number]
export function cleanMarkdownEnv(env: CleanMarkdownEnv, excludes: WhiteListUnion[] = []): CleanMarkdownEnv {
const result: CleanMarkdownEnv = {}
for (const key of WHITE_LIST) {
if (excludes.includes(key))
continue
result[key] = env[key] as string
}
return result
}