|
|
|
@ -40,8 +40,14 @@ export interface MarkdownParsedData {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface MarkdownRenderer {
|
|
|
|
|
__path: string
|
|
|
|
|
__relativePath: string
|
|
|
|
|
__data: MarkdownParsedData
|
|
|
|
|
render: (src: string, env?: any) => { html: string; data: any }
|
|
|
|
|
render: (
|
|
|
|
|
src: string,
|
|
|
|
|
path: string,
|
|
|
|
|
relatiovePath: string
|
|
|
|
|
) => { html: string; data: any }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export type { Header }
|
|
|
|
@ -94,17 +100,20 @@ export const createMarkdownRenderer = (
|
|
|
|
|
md.use(lineNumberPlugin)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const wrappedMd = md as any as MarkdownRenderer
|
|
|
|
|
|
|
|
|
|
// wrap render so that we can return both the html and extracted data.
|
|
|
|
|
const render = md.render
|
|
|
|
|
const wrappedRender: MarkdownRenderer['render'] = (src) => {
|
|
|
|
|
;(md as any).__data = {}
|
|
|
|
|
wrappedMd.render = (src, path, relativePath) => {
|
|
|
|
|
wrappedMd.__data = {}
|
|
|
|
|
wrappedMd.__path = path
|
|
|
|
|
wrappedMd.__relativePath = relativePath
|
|
|
|
|
const html = render.call(md, src)
|
|
|
|
|
return {
|
|
|
|
|
html,
|
|
|
|
|
data: (md as any).__data
|
|
|
|
|
data: wrappedMd.__data
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
;(md as any).render = wrappedRender
|
|
|
|
|
|
|
|
|
|
return md as any
|
|
|
|
|
return wrappedMd
|
|
|
|
|
}
|
|
|
|
|