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

Can you add exclude a header from toc in secondary sidebar? #313

Closed
ngtrian opened this issue May 6, 2017 · 11 comments
Closed

Can you add exclude a header from toc in secondary sidebar? #313

ngtrian opened this issue May 6, 2017 · 11 comments

Comments

@ngtrian
Copy link

ngtrian commented May 6, 2017

Description

Can you add exclude a header from toc in secondary sidebar? I want add a header 5 to content, but I don't want display header 5 in secondary sidebar (md-sidebar md-sidebar--secondary)

Package versions

  • Python: 2.7.12
  • MkDocs: 0.16.3
  • Material: 1.6.1
@facelessuser
Copy link
Contributor

I believe something like this could help: #136, but you'd have to adjust the CSS to target your desired level.

@ngtrian
Copy link
Author

ngtrian commented May 7, 2017

This can not solve my problem. I want to hide heading 5 not level 2 in toc

Because I want to use headings in documents in a certain file, But I do not want them to appear in TOC.

@facelessuser
Copy link
Contributor

That isn't what #136 means. The person wanted to hide anything greater than 2 levels deep (this isn't referring to h1). So they wanted to show h2 and h3, so the solution hides h4+. If I understand correctly, you want to hide h5+, so you would need to tweak the CSS to start hiding 1 level deeper.

Unless I am still misunderstanding.

@ngtrian
Copy link
Author

ngtrian commented May 7, 2017

Simple I want to use a heading (h5) in documents in a certain file, But I do not want them to appear in TOC.
Here I use heading 5 less used to avoid overlapping with the heading of other markdown files

@facelessuser
Copy link
Contributor

At most, all that can be done is excluding a certain header level with CSS. So the solution above is based on header levels (forth in the nested hierarchy), but not header type (h5). The TOC generator (which is separate from this theme), does not have the ability to exclude a specific header type. And the TOC in the sidebar does not track the header type, but simply nests them in a logical hierarchy.

So targeting specifically h5 in the sidebar TOC (with the purpose of hiding it) is not possible, but targeting the 4th level nesting is possible.

screenshot 2017-05-06 23 39 00

label[for="toc"]+.md-nav__list .md-nav__list .md-nav__list .md-nav__list {
    display: none;
}

But if you skipped nesting levels, for example nest h5 directly under h2, then this would not hide h5 as it would not be at the proper nested level. So if this is not sufficient for you, I don't think what you want is possible

@squidfunk
Copy link
Owner

When you specify your heading in the Markdown file not like this:

##### Heading

but like this:

<h5>Heading</h5>

It will render correctly and won't appear in the table of contents.

@ngtrian
Copy link
Author

ngtrian commented May 7, 2017

thank a tip of @squidfunk .

@facelessuser
Copy link
Contributor

Never realized this was built-in to the current TOC plugin. Nice to know!

@squidfunk
Copy link
Owner

Well, technically it isn't. The TOC plugin is only parsing the Markdown headline definitions, so by using HTML tags, you sneak them past the TOC plugin unoticed, as it doesn't parse the HTML. Closing this, as it seems to be solved. Otherwise please re-open.

@chrimaho
Copy link
Contributor

Hi @squidfunk , is this still the case? It seems like now the TOC is able to render headings which are parsed using HTML tags. Is there any other way in which we can exclude any header from being added to the TOC?

Thank you.

@squidfunk
Copy link
Owner

squidfunk commented Jan 10, 2023

The fix mentioned in #313 (comment) should still work, and it should be unaffected by the new built-in typeset plugin. If that's not the case, please open a new bug report.

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

4 participants