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

Ability to exclude headings from TOC #15

Closed
mashdot opened this issue Jul 13, 2019 · 8 comments
Closed

Ability to exclude headings from TOC #15

mashdot opened this issue Jul 13, 2019 · 8 comments

Comments

@mashdot
Copy link

mashdot commented Jul 13, 2019

I am migrating from using Kramdown, and wondered if there is functionality to exclude headers from the TOC?

In Kramdown...

# Header 1

## Header 2
{:.no_toc}

## Header 3

Would result in just creating the TOC with "Header 1" and "Header 3", excluding "Header 2" from the list.

Reference: https://kramdown.gettalong.org/converter/html.html#toc

@nagaozen
Copy link
Owner

Maybe with an option? Exclude: []?

@nagaozen
Copy link
Owner

nagaozen commented Jul 18, 2019

Just another question, when using this syntax, you end up with a paragraph with {:.no_toc} text, don't you?

`

  1. Header 1
    1. Header 2
    2. Header 3

§ Header 1

§ Header 2

{:.no_toc}

§ Header 3

Lorem ipsum dolorem sit amet

`

So this is also involves other plugins, or no?

@nagaozen
Copy link
Owner

Oh, I see ... you are probably using markdown-it-kramdown-attrs. This should be mentioned when opening the issue.

@mashdot
Copy link
Author

mashdot commented Jul 18, 2019

Middleman just uses Kramdown by default

- TOC
{:toc}

# Header 1

## Header 2
{:.no_toc}

## Header 3

Results in...

<ul id="markdown-toc">
  <li><a href="#header-1" id="markdown-toc-header-1">Header 1</a>    <ul>
      <li><a href="#header-3" id="markdown-toc-header-3">Header 3</a></li>
    </ul>
  </li>
</ul>

<h1 id="header-1">Header 1</h1>

<h2 class="no_toc" id="header-2">Header 2</h2>

<h2 id="header-3">Header 3</h2>

@nagaozen
Copy link
Owner

Just noticed that it's already possible to exclude headings from TOC using level array notation. For example: level: [1,3] will only make a table of contents for headers H1 and H3

@nagaozen nagaozen closed this as completed Aug 1, 2019
@mashdot
Copy link
Author

mashdot commented Aug 1, 2019

Thanks @nagaozen that excludes all headers of a certain level. I was looking to exclude a specific header instance. This is useful if you want to keep the headings in an article, but perhaps just exclude one such as an aside block.

@vladfaust
Copy link

vladfaust commented Aug 27, 2020

The issue is still relevant.

One workaround I've found is to define headers with html tags, e.g .<h2>My header</h2> instead of ## My header. This way, it won't be included in ToC. However, it would also be ignored by other plugins.

I wish there was a way to ignore a Markdown-defined header specifically by this plugin.

@joapuiib
Copy link

joapuiib commented Dec 9, 2020

Looking exactly for this. It would be nice to exclude specific headers from the TOC, as kramdown does.

Maybe exclude them based on their class. Actually, it could go both ways: exclude if "no_toc" or include if "toc".

No need to use markdown-it-kramdown-attrs, but possible.

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