Closed Archie-2021 closed 2 years ago
Can you share with me an example + a screenshot if at all possible.
Can you share with me an example + a screenshot if at all possible.
Look how lvl1 heading shown at lvl2 becauae Toc on top of it starts at lvl2
You cannot have a level 2 heading first in the document and then have a level 1 heading.
I don't think this can be fixed. The first heading in a document should be the lowest (level 1). It's quite difficult to explain so hopefully images will help.
In this example, I moved toc to level 1, this fixed the indentation.
The logic that is in play is:
So in your example:
Removing the subtract logic produces invalid markdown which won't render
You are using headings a little unconventionally. Headings aren't for style, they provide lexical meaning to a document.
If your documents were structured like this, by having a top level 1 heading, that will fix your issue. With the logic that we're forced to apply by subtracting the first headings level in a document by a headings level:
# Page title
## toc
## lvl1
### lvl2
That will fix your issue. Alternatively, make toc
a level 1 header
Short Answer
You cannot have a level 2 heading first in the document and then have a level 1 heading.
Detailed Answer
I don't think this can be fixed. The first heading in a document should be the lowest (level 1). It's quite difficult to explain so hopefully images will help.
In this example, I moved toc to level 1, this fixed the indentation.
The logic that is in play is:
- Find all headings in a document
- Get take the first heading
- Get the level of that heading, this sets the basis of the indentation (we need indentation to render markdown lists correctly)
- For each heading we subtract the first headings level found in step 3 this is because we cannot have a list that has a first item that is indented more than the subsequent items, it produces invalid markdown.
So in your example:
toc = level 2
- 2 - 2 = 0 (no indentation)
lvl1 = level 1
- 1 - 2 = -1 (negative indentation isn't a think in markdown so it's 0)
Removing the subtract logic produces invalid markdown which won't render
Recommendation
You are using headings a little unconventionally. Headings aren't for style, they provide lexical meaning to a document.
If your documents were structured like this, by having a top level 1 heading, that will fix your issue. With the logic that we're forced to apply by subtracting the first headings level in a document by a headings level:
page title - level 1
- 1 - 1 = 0 (no indentation)
toc - level 2
- 2 - 1 = 1 (one level if indentation)
lvl1 - level 2
- 2 - 1 = 1
# Page title ## toc ## lvl1 ### lvl2
That will fix your issue. Alternatively, make
toc
a level 1 header
Thanks for your detailed explanation, I agree that my use of heading here is a bit unconventional but the thing is that I like folding and unfolding and separating document in manageable and referenceable chunks a lot and it is the only heading that I can do it in markdown. I will use a first level heading at the top for putting front matter out of the way after this. it is going to be a bit distracting and ugly but would do the job.
For example. I like to embed the TOC and some dataview metadata stuff at the top of my notes in a lvl4 heading so that I can fold it out of the way. But if I do that all the indentation above the lvl 4 get removed.