badboy / mdbook-toc

A preprocessor for mdbook to add inline Table of Contents support.
Mozilla Public License 2.0
163 stars 20 forks source link

Support and strip heading attributes #39

Closed dnaka91 closed 1 year ago

dnaka91 commented 1 year ago

Currently, I'm making pretty heaving use of heading attributes, to have custom fragment identifier for my headings.

Sadly, they're currently not handled by mdbook-toc, which causes wrong names in the generated table of contents.

I saw that the pulldown-cmark crate has support for this. The necessary steps are probably to add the Options::ENABLE_HEADING_ATTRIBUTES and then handle the Tag::Heading properly.

Example

The following allows me to have the same header names in different sections, and still have reasonable well named fragment anchors.

# My content

## A

### Schema {#a-schema}

## B

### Schema {#b-schema}

Then mdbook-toc includes those creating a ToC like this:

- [A](#a)
  - [Schema {#a-schema}](#schema-a-schema)
- [B](#b)
  - [Schema {#b-schema}](#schema-b-schema)

What it should render, is the following

- [A](#a)
  - [Schema](#a-schema)
- [B](#b)
  - [Schema](#b-schema)
badboy commented 1 year ago

Feel free to send a PR handling that.

dnaka91 commented 1 year ago

Absolutely. Will prepare the changes in the coming days and send it your way 👍

badboy commented 1 year ago

Cool, I'll make sure to have some free cycles for review & merge then