Leverage redcarpets TOC rendering
Redcarpet comes with a TOC-renderer. I'd like to use that one and drafted a pretty rough implementation in my fork.
It is already usable like the following: Copy (better: symlink) the relevant file (e.g. README.md) while changing its extension to .md_toc (e.g. README.md_toc: ln -s README.md README.md_toc). Then call render as usally, but run through the file twice:
<%= render 'markdown.md_toc' %>
<%= render 'markdown.md' %>
In the implementation as-is, you have to specify the full filename I guess (didnt try without, shouldnt work) to dissociate between the two files (alternative, rename to something like README_TOC.md_toc.
I agree that the API is not yet ready for winning awards, but its just a hacky sketch for now. What do you think about that feature? How would you like the API to look like (maybe render_toc 'readme'?).
If you like, we could discuss this in a PR as well.
Hi @fwolfst thanks for this. I agree it's a good idea to have TOC.
I think it's better to have a separate render function than to change the filename. Therefore, render_toc sounds good.
If there weren't https://github.com/rails/rails/issues/35222, one could also use
render partial 'readme', format: :md_toc . But it wont work due to a bug (takes the wrong TemplateHandler).
I am not sure if I can push further the TOC rendering soon, or if that has to wait a decade.