Skip to content

fix: prevent mixed =/- chars in Setext-style headings (fixes #1604)#1605

Open
Jah-yee wants to merge 1 commit into
Python-Markdown:masterfrom
Jah-yee:fix/setext-heading-regex
Open

fix: prevent mixed =/- chars in Setext-style headings (fixes #1604)#1605
Jah-yee wants to merge 1 commit into
Python-Markdown:masterfrom
Jah-yee:fix/setext-heading-regex

Conversation

@Jah-yee
Copy link
Copy Markdown

@Jah-yee Jah-yee commented May 22, 2026

Description

The regex [=-]+ incorrectly matches mixed runs like =-=- or -=-= as Setext-style headings, even though only all-= (H1) or all-- (H2) are valid.

Fix

Changed regex from [=-]+ to (?:[=]+|[-]+).

Test

  • Mixed =/- → NOT headings ✓
  • All = → H1 ✓
  • All - → H2 ✓

Fixes #1604

The regex [=-]+ incorrectly matches mixed runs like '=-' or '-='
which are not valid Setext headers (only = or - alone are valid).

Fix using (?:[=]+|[-]+) to match only homogeneous runs.

Fixes issue Python-Markdown#1604
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect parsing of Setext-style headings

1 participant