Skip to content

[Feature Request] Ignore header in table of contents (toc) #1178

Open
@j1elo

Description

@j1elo

It could be useful, and after seeing the code, almost trivial to add support to skip / ignore / omit some of the document headers, using a header attribute.

I'm thinking of something like this: https://bookdown.org/yihui/rmarkdown-cookbook/toc-unlisted.html

Using the Attribute Lists extension is a great way to allow users fine tune the desired behavior. Right now, the TOC extension allows using just one, data-toc-label, so I'd propose adding a data-toc-unlisted which disables adding the header to the TOC.

Code would be pretty minimal, something like this (but I'm no Python programmer so syntax may be off):

for el in doc.iter():
    ....

    # Check if data-toc-unlisted attribute is present, to skip current element
    if 'data-toc-unlisted' in el.attrib:
        del el.attrib['data-toc-unlisted']  # Not sure if deleting the attr is really needed
        continue                            # This is the key point: to skip the current element altogether

    ...

Let me take the chance to say thank you to all maintainers and devs of this project!

Metadata

Metadata

Assignees

No one assigned

    Labels

    extensionRelated to one or more of the included extensions.featureFeature request.someday-maybeApproved low priority request.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions