add 添加脚注支持 footnote

This commit is contained in:
tianyaxiang 2025-02-28 11:40:40 +08:00
parent 5d6f5cf38e
commit cad0ac5221
3 changed files with 14 additions and 7 deletions

View File

@ -58,13 +58,6 @@ export class MarkdownParser {
return token as any
}
return undefined
},
renderer(token: any) {
const footnoteStyle = (options?.inline?.footnote || {})
const styleStr = Object.entries(footnoteStyle)
.map(([key, value]) => `${key}:${value}`)
.join(';')
return `<sup${styleStr ? ` style="${styleStr}"` : ''}><a href="#fn-${token.text}">[${token.text}]</a></sup>`
}
}]
})

View File

@ -370,6 +370,13 @@ export class MarkdownRenderer {
const styleStr = cssPropertiesToString(delStyle)
return `<del${styleStr ? ` style="${styleStr}"` : ''}>${text}</del>`
}
// 添加脚注支持
this.renderer.footnote = (token: any) => {
const footnoteStyle = (this.options.inline?.footnote || {})
const styleStr = cssPropertiesToString(footnoteStyle)
return `<sup${styleStr ? ` style="${styleStr}"` : ''}><a href="#fn-${token.text}">[${token.text}]</a></sup>`
}
}
public getRenderer(): typeof marked.Renderer.prototype {

7
src/types/marked.d.ts vendored Normal file
View File

@ -0,0 +1,7 @@
import { marked } from 'marked';
declare module 'marked' {
interface RendererThis {
footnote: (token: any) => string;
}
}