remarkjs / remark-toc

plugin to generate a table of contents (TOC)

Home Page:https://remark.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

usage from an AST

tmcw opened this issue · comments

I'm generating an AST for a Markdown file and would like to use mdast-toc to add a table of contents, but it seems like this will only work when processing an existing markdown file, rather than generating one from scratch. Should I generate into a file and then re-transform it, or is there a way to use a transformer without starting out with a file?

commented

Sorry, I'm on my mobile rather than my mac, so you'll have to do without links: use mdast.parse together with mdast.run, that should do the trick without a file!

commented

Here are the links for mdast.parse and mdast.run, hope that makes it a bit more clear. You won’t need a file for that, if you’d like to get access to that you’ll have to pass a done callback to mdast.run which receives a file as a parameter.