Skip to content

Allow TOC element to use a custom CSS class #1224

Closed
@jnns

Description

@jnns
[TOC]
# Header 1

will currently generate the following HTML:

<div class="toc">
  <ul>
    <li><a href="#header-1">Header 1</a></li>
  </ul>
</div>
<h1 id="header-1">Header 1</h1>

The class="toc" cannot be changed, although using custom classes are supported for anchorlinks (anchorlink_class) and permalinks (permalink_class).

I suggest that another config parameter toc_class that defaults to the current class toc is introduced. This is useful if in use with CSS frameworks that apply certain styles to prose content but allow disabling the additional styles when a certain class is present. For TailwindCSS, the extension could be called like so:

md = markdown.Markdown(extensions=[TocExtension(toc_class="toc not-prose")]

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmedConfirmed bug report or approved feature request.extensionRelated to one or more of the included extensions.featureFeature request.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions