TOC generation unclear
CVTJNII opened this issue · 2 comments
While converting markdown to HTML it is unclear on how to generate a table of contents. Enabling :generate_toc adds the a tags, however a TOC isn't added. In searching for a solution it appears a TOC tag needs to be added to the markdown (which makes sense) however I cannot find any documentation on what that tag is or how to specify it. Grepping the code for 'toc.*token' yields no hits, and the token isn't mentioned in the documentation. Please clarify how to specify the TOC token in code, thanks.
In examining the test suite, there is an API for extracting the generated TOC itself. Offhand I do not know whether there is a way to signal to insert that generated TOC into the Markdown output.
Relevant snippet from /test/rdiscount_test.rb
:
def test_that_generate_toc_sets_toc_ids
rd = RDiscount.new("# Level 1\n\n## Level 2", :generate_toc)
assert rd.generate_toc
assert_equal %(<a name="Level.1"></a>\n<h1>Level 1</h1>\n\n<a name="Level.2"></a>\n<h2>Level 2</h2>\n), rd.to_html
end
def test_should_get_the_generated_toc
rd = RDiscount.new("# Level 1\n\n## Level 2", :generate_toc)
exp = %(<ul>\n <li><a href=\"#Level.1\">Level 1</a>\n <ul>\n <li><a href=\"#Level.2\">Level 2</a></li>\n </ul>\n </li>\n</ul>)
assert_equal exp, rd.toc_content.strip
end
You might try asking https://github.com/Orc , the maintainer of Discount about how to get the generated TOC inserted into the Markdown output. Although I know like me he doesn't personally use the TOC feature either.
No further interest has been shown in this issue for several years. Closing.