Skip to content

Incorrect table of contents for additional title spacing with mdformat 0.7.22 #15

@KristofBCoding

Description

@KristofBCoding

Mdformat trims superfluous whitespace in 0.7.22 when formatting text. Because heading information is loaded before any markdown formatting, this can lead to incorrect toc entries. Consider the following example:

<!-- mdformat-toc start --slug=github --no-anchors --maxlevel=6 --minlevel=1 -->

# foo     bar
.

Which, when running mdformat with this plugin gives:

<!-- mdformat-toc start --slug=github --no-anchors --maxlevel=6 --minlevel=1 -->

- [foo     bar](#foo-----bar)

<!-- mdformat-toc end -->

# foo bar

Spacing in the title was formatted away, which is now wrong in the table of contents because that was generated before formatting.

Running twice would fix this, but this isn't exactly clean, especially when using pre-commit.

Note that you can easily see this go wrong in the existing tests, one of them will fail as soon as you install 0.7.22 of mdformat.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions