MCPcopy
hub / github.com/docsifyjs/docsify / headingCompiler

Function headingCompiler

src/core/render/compiler/headline.js:4–39  ·  view source on GitHub ↗
({ renderer, router, _self })

Source from the content-addressed store, hash-verified

2import { slugify } from './slugify';
3
4export const headingCompiler = ({ renderer, router, _self }) =>
5 (renderer.code = (text, level) => {
6 let { str, config } = getAndRemoveConfig(text);
7 const nextToc = { level, title: removeAtag(str) };
8
9 if (/<!-- {docsify-ignore} -->/g.test(str)) {
10 str = str.replace('<!-- {docsify-ignore} -->', '');
11 nextToc.title = removeAtag(str);
12 nextToc.ignoreSubHeading = true;
13 }
14
15 if (/{docsify-ignore}/g.test(str)) {
16 str = str.replace('{docsify-ignore}', '');
17 nextToc.title = removeAtag(str);
18 nextToc.ignoreSubHeading = true;
19 }
20
21 if (/<!-- {docsify-ignore-all} -->/g.test(str)) {
22 str = str.replace('<!-- {docsify-ignore-all} -->', '');
23 nextToc.title = removeAtag(str);
24 nextToc.ignoreAllSubs = true;
25 }
26
27 if (/{docsify-ignore-all}/g.test(str)) {
28 str = str.replace('{docsify-ignore-all}', '');
29 nextToc.title = removeAtag(str);
30 nextToc.ignoreAllSubs = true;
31 }
32
33 const slug = slugify(config.id || str);
34 const url = router.toURL(router.getCurrentPath(), { id: slug });
35 nextToc.slug = url;
36 _self.toc.push(nextToc);
37
38 return `<h${level} id="${slug}"><a href="${url}" data-id="${slug}" class="anchor"><span>${str}</span></a></h${level}>`;
39 });

Callers

nothing calls this directly

Calls 5

getAndRemoveConfigFunction · 0.90
removeAtagFunction · 0.90
slugifyFunction · 0.90
toURLMethod · 0.45
getCurrentPathMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…