vcarl/remark-headings

Support for anchor tags

jrson83 opened this issue · 2 comments

Hey,
I'm using the plugin to get the headings from .mdx files to display them in a "Contents-List" as link with anchors and Intersection Observer in a sidebar. It would be totally great if you could add a third, maybe optional object anchor and convert the values you already have to lower-case and replace whitespace with dash . So like:

[
  {"depth": 1, "value": "Heading 1", "anchor": "#heading-1"},
  {"depth": 2, "value": "Heading 2", "anchor": "#heading-2"},
  {"depth": 3, "value": "Heading 3", "anchor": "#heading-3"},
]
vcarl commented

I think this is simpler to solve with a separate tool, rather than some kind of configuration on this plugin. Can use slugger to parse this info:

headings.map(x => ({...x, anchor: slugger(x.value) }))

I think this is simpler to solve with a separate tool, rather than some kind of configuration on this plugin. Can use slugger to parse this info:

headings.map(x => ({...x, anchor: slugger(x.value) }))

Ok, I will try, thank you for the info.