Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function toHtml (parent, tree) {
if (!tree) return []
unistVisit(tree, 'link', node => {
if (/^[\w#.]+$/.test(node.url)) {
let ref = node.children[0].value
if (ref.startsWith('#')) {
if (!parent) throw new Error(`Unknown parent for ${ ref }`)
ref = parent + ref
}
node.url = '#' + toSlug(ref.replace(/#/g, '-'))
}
})
return remarkRehype()(tree).children
}