Skip to content

Allow TOC element to be fully customizable #1293

Closed as not planned
Closed as not planned
@pauloxnet

Description

@pauloxnet
[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 div element cannot be changed and so it is for the title span element and its toctitle class.

I suggest that other config parameters (toc_tag, title_class, title_tag) that defaults to their current defaults are introduced.

This would be very useful for producing semantic HTML, using specific HMTL elements.

For example to use the details disclosure element as toc, the extension could be called like so:

md = markdown.Markdown(extensions=[TocExtension(
    title='Summary',
    title_class="",
    title_tag="summary",
    toc_class="",
    toc_tag="details"
)]]
<details>
<summary>Summary</summary>
<ul>
<li><a href="#header">Header</a></li>
</ul>
</details>
<h1 id="header">Header</h1>

This will render an initially closed details element with a summary:


Summary

Header

Metadata

Metadata

Assignees

No one assigned

    Labels

    3rd-partyShould be implemented as a third party extension.extensionRelated to one or more of the included extensions.featureFeature request.needs-decisionA decision needs to be made regarding request.wontfixThe issue will not be fixed for the stated reasons.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions