macdown icon indicating copy to clipboard operation
macdown copied to clipboard

Generate full TOC in Markdown

Open nicholaelaw opened this issue 9 years ago • 11 comments

I looked around and did not see any issues related to this topic.

I sometimes want to generate a toc at the beginning section of a long document and for now I'm doing it by hand:

TOC:
[Section 1]({{page.url}}/#section1
[Section 2]({{page.url}}/#section2
......
<div id='section1'/>
##Section 1
......
<div id='section2'/>
##Section 2

But this messes up the preview. Seen in the screenshot. macdown-toc-screenshot

At first texts immediately after the div mark eg. section titles stops rendering, and after a few saves whole sections are showing in plain text. Maths and HTML stays fine, and the file renders fine in Jekyll, just not in MacDown Preview.

Also in the screenshot you can see I used the liquid mark {% raw %} which MacDown doesn't recognize. It would be nice MacDown can process it.

nicholaelaw avatar Aug 29 '15 10:08 nicholaelaw

Also also, it would be nice if MacDown can generate TOC for us. Not just in the output like some editors do it, but actually insert the marks into the document.

Edit: typos.

nicholaelaw avatar Aug 29 '15 10:08 nicholaelaw

You can let MacDown generate TOC by enabling the feature in the Preferences, and insert [toc] in the document.

uranusjr avatar Aug 29 '15 11:08 uranusjr

OK, I'll try when I get home. What about the preview issue? Is there something I did wrong?

nicholaelaw avatar Aug 29 '15 11:08 nicholaelaw

What version are you using? The plain text problem should have been resolved some time ago.

uranusjr avatar Aug 29 '15 13:08 uranusjr

Hmm……strange. I'll have to get back to you on that but I think I'm using the latest version, based on the fact that I only downloaded and started using MacDown last week, and because I checked updates this afternoon and there was no update. I'll follow up with more definitive answer later tonight. Thanks for your time though.

nicholaelaw avatar Aug 29 '15 14:08 nicholaelaw

No need to worry, I was just checking to make sure. What you experienced might as well be another bug, not the one I fixed.

uranusjr avatar Aug 29 '15 14:08 uranusjr

OK, I've checked. I'm running version 0.5(670), which should be the latest. So I'm not sure if I did something wrong or there is indeed a bug.

As for the TOC generation feature, I actually meant something different. What the "Detect table of content token" option does is to generate a TOC in the rendered document. Which is nice if that is the end of the workflow.

What I was suggesting, was to actually insert the code for a table of content, much like the one I made manually. There was a script that does this, but it wasn't an integrated solution, among other problems.

nicholaelaw avatar Aug 29 '15 17:08 nicholaelaw

I second this feature request. Instead of having TOC as preview, please help to generate the markdown syntax for the TOC. The use case for this is to copy the markdown syntax as is (with TOC) to elsewhere (Github README / wiki) and the TOC is still available.

ghost avatar Feb 02 '16 02:02 ghost

+1 for me, this is the most useful feature a markdown editor can offer

[toc] is not sufficient when the intended consumer of the document will not be using macdown

Could we do something with metadata in a comment to allow macdown to control the TOC a la [toc]?

e.g.

<!-- macdown toc start - do not edit -->
this section would include markdown automatically generated by macdown
and macdown would automatically update it when the document changes
<!-- macdown toc end - do not edit -->

eedwards-sk avatar Aug 30 '18 15:08 eedwards-sk

+1

I'd love a way to generate the ToC markdown.

igustafson avatar Jan 21 '19 21:01 igustafson

Habe you tried https://derlin.github.io/bitdowntoc? It supports github and also has a CLI (https://github.com/derlin/bitdowntoc)

A universal Markdown TOC generator with presets for GitHub, BitBucket Server, Gitlab, dev.to, and more! Open-source, free, no trackers.

derlin avatar Mar 31 '24 21:03 derlin