syntax-tree/mdast-util-toc

Add `prefix` support

Kikobeats opened this issue · 1 comments

Problem

I'm generating a toc using mdast-util-toc but, before this, I sanetize my content using rehype-sanitize and hast-util-sanitize/lib/github.

This GitHub preset do a set of things related to sanitizing the content; one of them is to prefix urls by default.

Based on this premise, If I sanitize my content and then I tried to generate the Table of Content, the links of the table are not properly linked since they are not prefixed.

Subject of the feature

Just adding the ability to prefix the urls to have the same link src than the content should be enough

Thanks for raising this @Kikobeats!

Note: I believe the bug is because it’s the other way around: first the toc is generated, then the heading ids are prefixed. I think that if it were the way you described, the toc would include links to the prefixed ids!

Aside: An alternative solution would be to do the toc generation in hast. But that’s a much bigger endeavour, whereas the fix here is small. So I do propose this as an easy fix.