Generate TOC (table of contents)
See original GitHub issueIs it possible to automatically generate table content of all headings, like by placing some html markup on a page ? Something like that :
<div class="summary"></div>
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:14 (3 by maintainers)
Top Results From Across the Web
GitHub Wiki TOC generator
GitHub Wiki TOC generator This page uses markdown-toc library to generate your MarkDown TOC online.
Read more >How To: Create a Clickable Table of Contents (TOC)
Under Styles at the top (when you are on the Home window in Word), click on Heading 1 (do this for each section...
Read more >HOWTO-use Microsoft Word Table of Content (TOC) Generator
Microsoft Word TOC generator is a very useful tool to automatically generate and update the table of contents for a Microsoft Word document....
Read more >How to create / update a table of contents in Microsoft Word
So now you have assigned the first main section of your document. Keep it up! Go on scrolling through the text and selecting...
Read more >Word Tips: How to Create a Table of Contents in Word
Now for the easy part! Once you've applied heading styles, you can insert your table of contents in just a few clicks. Navigate...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If you want to generate a ToC that respects heading levels, the following will create a markdown formatted TOC for you using the Marked parser and default slugger. It returns a list indented with each heading level, linking to the anchor of each heading in the document.
So something like
Will be transformed to…
To use it with md-to-pdf read the file, parse its ToC and prefix it to the content option.
@designel
The
parseToc(md)
function takes a markdown string, walks over all headings (# title
) and then returns a string of markdown that can be used directly as a table of contents. You run it separately or before rendering the PDF.You can prepend the new piece of markdown to the actual MD you pass to Marked to render the final PDF.
How it works:
The ‘renderer’ is an config object for marked that takes plugins. We create a plugin that overrides the default header rendering and instead takes all the info about that heading and puts it in an array. Level is the header level (i.e.
# Level 1, ## level 2
.Which basically creates something like
This piece turns the above data into markdown:
creates: