question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exclude heading from toc globally

See original GitHub issue

What is the problem?

I want to exclude the heading “# On this page” from my workspace toc globally. I reviewed the instructions and it seems it might be possible. I’m not able to figure out the right syntax.

How can I reproduce it?

"markdown.extension.toc.omittedFromToc": {
    "/Users/{users}/Documents/{documentation-folder}":[
        "# On this page"
    ]
},

Is there any error message in the console?


Proposals

  • Add wildcard support to the omittedFromToc configuration. (1 vote)
  • Add an option to exclude headings before the position of the TOC. (2 votes)

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:6
  • Comments:18 (5 by maintainers)

github_iconTop GitHub Comments

14reactions
hpractvcommented, Apr 1, 2021

I think the easiest change to understand would be to make the path wildcard enabled:

"markdown.extension.toc.omittedFromToc": {
    "*/*.md": [
        "# index"
    ]
},

Also, as an aside, it would be nice if the string being ignored could be done in a case insensitive way. Otherwise, you’d have to add "# Index" and "# INDEX" and hope that "iNdex" isn’t used.

2reactions
Lemminghcommented, Jan 18, 2022

A sketch of the “exclude-heading” setting I talked above:

type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;

/**
 * @param level - The heading level.
 * @param content - The raw content of the heading according to the CommonMark Spec. Can be multiline.
 */
type HeadingSelector = [level: HeadingLevel, content: string];

/**
 * The shape in `settings.json`.
 */
interface UserSetting {
    [path: string]: HeadingSelector[];
}

interface InternalSetting {
    /**
     * The path filter.
     */
    path: RegExp;

    selectors: HeadingSelector[];
}

/**
 * The setting is managed as a Map at runtime.
 */
type InternalRegistry = Map<string, InternalSetting>;

const config: UserSetting = {
    "^docs/demo/emoji-[^/]+\\.md$": [[2, "😜 TOC"]],
    "^docs/.*\\p{Script=Han}.*\\.md$": [[2, "目录"]],
};

const s: InternalRegistry = new Map<string, InternalSetting>(
    Array.from(Object.entries(config), ([p, selectors]): [string, InternalSetting] => {
        const path = new RegExp(p, "u");
        return [path.source, { path, selectors }];
    })
);
Read more comments on GitHub >

github_iconTop Results From Across the Web

Possible to exclude levels in outline list from table of ...
I need to be able to generate a table of contents that includes the Section Heading and Subsection Headings, but not the (a)...
Read more >
Quick Tip: How to exclude headings from the Table of ...
Use the Custom Table of Content … in the “Table of Contents” drop down. Look under “General”, and “Show Levels” then change it...
Read more >
4.18 Omit a heading in the table of contents | R Markdown ...
If you do not want certain section headings to be included in the table of contents, you can add two classes to the...
Read more >
Non-TOC headings within a reStructuredText page
Note: in step (3), you could define the CSS selectors more broadly or narrowly. If the new class names are globally unique, the...
Read more >
Headings and Table of contents
Note that the toc global is a flat array, so you can easily cut out unwanted nodes or insert extra nodes, and create...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found