vscode-markdown icon indicating copy to clipboard operation
vscode-markdown copied to clipboard

Set the TOC levels range at document level

Open arnaduga opened this issue 2 years ago • 6 comments

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)

arnaduga avatar Feb 10 '22 10:02 arnaduga

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.

rcdailey avatar Apr 17 '22 18:04 rcdailey

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.

yzhang-gh avatar Apr 18 '22 00:04 yzhang-gh

@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.

rcdailey avatar Apr 18 '22 16:04 rcdailey

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

I see. Then there is no workaround for now.

yzhang-gh avatar Apr 18 '22 17:04 yzhang-gh

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!

prlcutting avatar Aug 12 '22 19:08 prlcutting

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

ts78 avatar Sep 02 '22 09:09 ts78