MCPcopy Index your code
hub / github.com/markmap/markmap / transform

Function transform

packages/markmap-lib/src/plugins/frontmatter/index.ts:9–38  ·  view source on GitHub ↗
(transformHooks: ITransformHooks)

Source from the content-addressed store, hash-verified

7export 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
41function normalizeMarkmapJsonOptions(options?: Partial<IMarkmapJSONOptions>) {

Callers

nothing calls this directly

Calls 2

tapMethod · 0.80

Tested by

no test coverage detected