Skip to content

mdformat-toc removes escape when heading contains an escaped colon #548

@cdwilson

Description

@cdwilson

Describe the bug

context

running the following doc through mdformat with mdformat-toc enabled:

# Overview

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

## A heading with\:a colon

Some more text

Produces this output:

# Overview

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

- [Overview](#overview)
  - [A heading with:a colon](#a-heading-witha-colon)

<!-- mdformat-toc end -->

## A heading with:a colon

Some more text

expectation
I expected the escape (\:) to be preserved in the header on format.

bug
But instead the escape is removed.

When linting the output doc with markdownlint-cli2, I get the following error:

❯ markdownlint-cli2 test.md
markdownlint-cli2 v0.18.1 (markdownlint v0.38.0)
Finding: test.md
Linting: 1 file(s)
Summary: 1 error(s)
test.md:4:5 MD051/link-fragments Link fragments should be valid [Context: "[A heading with:a colon](#a-heading-witha-colon)"]

Restoring the escape in the header fixes the linting error:

# Overview

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

- [Overview](#overview)
  - [A heading with:a colon](#a-heading-witha-colon)

<!-- mdformat-toc end -->

## A heading with\:a colon

Some more text
❯ markdownlint-cli2 test.md 
markdownlint-cli2 v0.18.1 (markdownlint v0.38.0)
Finding: test.md
Linting: 1 file(s)
Summary: 0 error(s)

See DavidAnson/markdownlint#1771 for more details.

Reproduce the bug

See above

List your environment

❯ mdformat --version
mdformat 0.7.22 (mdformat_frontmatter 2.0.8, mdformat-gfm 0.4.1, mdformat_gfm_alerts 2.0.0, mdformat_tables 1.0.0, mdformat_mkdocs 4.4.1, mdformat-toc 0.3.0, mdformat_footnote 0.1.1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions