MacDownApp / macdown

Open source Markdown editor for macOS.
https://macdown.uranusjr.com/
9.45k stars 1.09k forks source link

Generate full TOC in Markdown #431

Open nicholaelaw opened 9 years ago

nicholaelaw commented 9 years ago

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 commented 9 years ago

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.

uranusjr commented 9 years ago

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

nicholaelaw commented 9 years ago

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

uranusjr commented 9 years ago

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

nicholaelaw commented 9 years ago

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.

uranusjr commented 9 years ago

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.

nicholaelaw commented 9 years ago

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.

ghost commented 8 years ago

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.

eedwards-sk commented 6 years ago

+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 -->
igustafson commented 5 years ago

+1

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

derlin commented 7 months ago

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

Add a Table of Contents (TOC) to your Markdown Online
A universal Markdown TOC generator with presets for GitHub, BitBucket Server, Gitlab, dev.to, and more! Open-source, free, no trackers.