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

How can I omit a heading from TOC? #65

Closed
damusix opened this issue Jan 20, 2025 · 3 comments
Closed

How can I omit a heading from TOC? #65

damusix opened this issue Jan 20, 2025 · 3 comments

Comments

@damusix
Copy link

damusix commented Jan 20, 2025

For example, it doesn't make sense to include the first h1 since it's always at the top of the page

@cmaas
Copy link
Owner

cmaas commented Jan 20, 2025

You can't exclude a single heading. You can only exclude all headings of a type, for example, all h1:

const md = new MarkdownIt();
md.use(markdownItTOC, {
  "includeLevel": [2,3,4]
});

I do not plan to add support to exclude specific headings, because it's kinda weird. Markdown has no concept of a querySelector. The source document is Markdown, not HTML. You can't easily specify which headline you want to exclude.

If you want more fine-grained control, I recommend to move the TOC generation to the client by using my client-side web component: https://github.com/cmaas/table-of-contents-element

This way, you have full access to the DOM and can pass a querySelector as an attribute to exclude headings with a certain ID, class etc.

@damusix
Copy link
Author

damusix commented Jan 20, 2025

@cmaas In VSCode, the all in one markdown plugin allows you to omit by inserting an html comment <!-- omit from toc -->. I too think excluding all h1's would be awkward, but it would be useful to exclude some that don't contribute anything meaningful to the TOC.

EG:

Some main title


Everyone can agree that's kind of awkward to get scrolled to above the TOC.

@cmaas cmaas closed this as completed in fb1e1a4 Jan 21, 2025
@cmaas
Copy link
Owner

cmaas commented Jan 21, 2025

Good idea, I added this as you suggested in the just released version 0.9.0

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