Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrong TOC level #323

Closed
step- opened this issue Sep 24, 2023 · 15 comments
Closed

wrong TOC level #323

step- opened this issue Sep 24, 2023 · 15 comments

Comments

@step-
Copy link
Contributor

step- commented Sep 24, 2023

Minimal working example

# One
1

### Three
3

Description

In the minimal working example, pressing \wf should produce the following TOC

*Contents*
* [One](#One)
                * [Three](#One##Three)

but instead it produces:

*Contents*
        * [Three](#One##Three)

with the level-3 heading promoted to level 2. Consequently, following the link always jumps to the level 1 heading.

The point is that I would like to be able to jump to the level 3 heading from the generated TOC even if there is no intermediate level 2 heading in the markdown file.

@lervag
Copy link
Owner

lervag commented Sep 25, 2023

This seems like a bug. I'll look into it.

@lervag
Copy link
Owner

lervag commented Sep 25, 2023

Or, at least, it is a bug that the link does not work.

How should the TOC look like for this file?

# One
1

### Three
3

## Two
2

### Two three
2.3

@step-
Copy link
Contributor Author

step- commented Sep 25, 2023

I think it should look like if there was a hidden level-2 heading between One an Three, except that the hidden heading's TOC entry should also be hidden.

@step-
Copy link
Contributor Author

step- commented Sep 25, 2023

I agree, it's more important for the link to work, that's the key point.

lervag added a commit that referenced this issue Sep 25, 2023
@lervag
Copy link
Owner

lervag commented Sep 25, 2023

I think it should look like if there was a hidden level-2 heading between One an Three, except that the hidden heading's TOC entry should also be hidden.

Not fully sure what you mean. Do you mean something like this (which is what we get today)?

*Contents*
* [One](#One)
        * [Three](#One#Three)
    * [Two](#One#Two)
        * [Two three](#One#Two#Two three)

I agree, it's more important for the link to work, that's the key point.

I think this is fixed now. Please update and test.

@lervag
Copy link
Owner

lervag commented Sep 25, 2023

I agree that it would be nice to avoid the extra indent if there are no middle sections (such as in your initial example). However, I don't see immediately a nice solution for implementing this that would not be quite "hacky". And so I'm wondering if it is worth the work to implement it.

@step-
Copy link
Contributor Author

step- commented Sep 25, 2023

Not fully sure what you mean. Do you mean something like this (which is what we get today)?

*Contents*
* [One](#One)
        * [Three](#One#Three)
    * [Two](#One#Two)
        * [Two three](#One#Two#Two three)

I mean this

Contents*
* [One](#One)
        * [Three](#One##Three)
    * [Two](#One#Two)
        * [Two three](#One#Two#Two three)

@lervag
Copy link
Owner

lervag commented Sep 25, 2023

That's the same as what I posted..?

@lervag
Copy link
Owner

lervag commented Sep 25, 2023

By the way, I pushed another fix that should ensure that the first entry of the TOC is also properly printed.

@step-
Copy link
Contributor Author

step- commented Sep 25, 2023

That's the same as what I posted..?

Yours #One#Three, mine #One##Three

@lervag
Copy link
Owner

lervag commented Sep 25, 2023

Ah; but I think One#Three is what we want here for the URLs to work correctly.

@step-
Copy link
Contributor Author

step- commented Sep 25, 2023

I'm happy as long as the link works. I'll test your fix and report back.

@lervag
Copy link
Owner

lervag commented Sep 25, 2023

Cool!

@step-
Copy link
Contributor Author

step- commented Sep 25, 2023

Looks good to me. Thank you!

@lervag
Copy link
Owner

lervag commented Sep 25, 2023

My pleasure, and thanks for raising the issue!

@lervag lervag closed this as completed Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants