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