Skip to content

Commit ea84fdb

Browse files
Wrap headings in anchor tag linking its slug
1 parent c157b3f commit ea84fdb

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/markdoc/nodes.mjs

+3-5
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,9 @@ const nodes = {
4141
let text = children.filter((child) => typeof child === 'string').join(' ')
4242
let id = attributes.id ?? slugify(text)
4343

44-
return new Tag(
45-
`h${node.attributes.level}`,
46-
{ ...attributes, id },
47-
children,
48-
)
44+
return new Tag(`a`, { href: `#${id}`, ...attributes }, [
45+
new Tag(`h${node.attributes.level}`, { id }, children),
46+
])
4947
},
5048
},
5149
th: {

0 commit comments

Comments
 (0)