mirror of
https://github.com/morten-olsen/http.md.git
synced 2026-02-08 00:46:28 +01:00
docs: stuff
This commit is contained in:
29
src/execution/handlers/handlers.toc.ts
Normal file
29
src/execution/handlers/handlers.toc.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { toc } from 'mdast-util-toc';
|
||||
import { type ExecutionHandler } from '../execution.js';
|
||||
|
||||
const tocHandler: ExecutionHandler = ({
|
||||
addStep,
|
||||
node,
|
||||
root,
|
||||
parent,
|
||||
index,
|
||||
}) => {
|
||||
if (node.type === 'leafDirective' && node.name === 'toc') {
|
||||
addStep({
|
||||
type: 'toc',
|
||||
node,
|
||||
action: async () => {
|
||||
const result = toc(root, {
|
||||
tight: true,
|
||||
minDepth: 2,
|
||||
})
|
||||
if (!parent || !parent.children || index === undefined) {
|
||||
throw new Error('Parent node is not valid');
|
||||
}
|
||||
parent.children.splice(index, 1, result.map as any);
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export { tocHandler };
|
||||
Reference in New Issue
Block a user