yzhang-gh / vscode-markdown

Markdown All in One
https://marketplace.visualstudio.com/items?itemName=yzhang.markdown-all-in-one
MIT License
2.89k stars 324 forks source link

Set the TOC levels range at document level #1078

Open arnaduga opened 2 years ago

arnaduga commented 2 years ago

Proposal

Today, you can set the TOC levels thanks to the extensions settings key markdown.extension.toc.levels.

However, it may happen documents do not have the same structure and range 1..3 is good for some of, whereas a 2..3 would be more appropriate.

An option in the document itself could be very useful:

<!-- toc.levels="1..2" -->
- [Introduction](#introduction)
- [Section1](#section1)
    - [Subsectionsection1](#subsection1)

or

<!-- toc.levels="1..3" -->
- [Introduction](#introduction)
- [Section1](#section1)
    - [Subsectionsection1](#subsection1)
        - [Conclusion](#conclusion)
rcdailey commented 2 years ago

Another option might be to use VS Code workspace settings, and be able to specify toc.levels per-file, like so:

{
  "markdown.extension.toc.levels": {
    "wiki/Upgrade-Guide.md": "2..2"
  }
}

Having said that, I personally prefer specifying it inline via HTML comment as the OP requested.

yzhang-gh commented 2 years ago

Thanks for the feedback. I agree this can be useful.

And for your case (@rcdailey), you can add <!-- omit in toc --> to the first-level heading if you already have toc levels 1..2 in your user or workspace settings.

rcdailey commented 2 years ago

@yzhang-gh I'm not sure what you are suggesting. In my case, I only want 2..2. And in my preferences, I have 2..6. And omit in toc only works per-header, right? So I'd have to repeat it for every single header below level 2. I'm not sure how that addresses the issue.

yzhang-gh commented 2 years ago

And in my preferences, I have 2..6.

I see. Then there is no workaround for now.

prlcutting commented 2 years ago

I recently came across the same need; that is, to be able to specify toc levels on a per file basis. I agree with the OP that in-lining something in the file itself (akin to <!-- omit in toc -->) is the most intuitive, discoverable and maintainable.

Thanks for an awesome VSCode extension - love it!

ts78 commented 2 years ago

Is this a duplicate of #208 ? Anyway, I would also vote for per document settings especially for TOC level range.