(transformHooks: ITransformHooks)
| 7 | export default definePlugin({ |
| 8 | name, |
| 9 | transform(transformHooks: ITransformHooks) { |
| 10 | transformHooks.beforeParse.tap((_md, context) => { |
| 11 | const { content } = context; |
| 12 | if (!/^---\r?\n/.test(content)) return; |
| 13 | const match = /\n---\r?\n/.exec(content); |
| 14 | if (!match) return; |
| 15 | const raw = content.slice(4, match.index).trimEnd(); |
| 16 | let frontmatter: typeof context.frontmatter; |
| 17 | try { |
| 18 | frontmatter = parse(raw.replace(/\r?\n|\r/g, '\n')); |
| 19 | if (frontmatter?.markmap) { |
| 20 | frontmatter.markmap = normalizeMarkmapJsonOptions( |
| 21 | frontmatter.markmap, |
| 22 | ); |
| 23 | } |
| 24 | } catch { |
| 25 | return; |
| 26 | } |
| 27 | context.frontmatter = frontmatter; |
| 28 | context.parserOptions = { |
| 29 | ...context.parserOptions, |
| 30 | ...frontmatter?.markmap?.htmlParser, |
| 31 | }; |
| 32 | context.frontmatterInfo = { |
| 33 | lines: content.slice(0, match.index).split('\n').length + 1, |
| 34 | offset: match.index + match[0].length, |
| 35 | }; |
| 36 | }); |
| 37 | return {}; |
| 38 | }, |
| 39 | }); |
| 40 | |
| 41 | function normalizeMarkmapJsonOptions(options?: Partial<IMarkmapJSONOptions>) { |
nothing calls this directly
no test coverage detected