import slugify from '@sindresorhus/slugify' export default async function (doc, rootNode, context) { const headingLevel = +rootNode.tail.split(' ')[0] const text = rootNode.tail.split(' ').slice(1).join(' ') const slug = slugify(text) const node = { type: rootNode.head, level: headingLevel, text, slug, class: '', href: '', children: [] } for await (const child of rootNode.children()) { if (child.is('class')) node.class = child.tail if (child.is('href')) node.href = child.tail } context.page.headings.push(node) return node }