Skip to content

Fix TOC labels for quoted HTML angle brackets - #1671

Merged
waylan merged 1 commit into
Python-Markdown:masterfrom
repzakske:fix/toc-quoted-html-attributes
Oct 22, 2026
Merged

waylan merged 1 commit into
Python-Markdown:masterfrom
repzakske:fix/toc-quoted-html-attributes

Conversation

@repzakske

@repzakske repzakske commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Description

With toc enabled, # <abbr title="Python > 3">Python</abbr> support
produces the TOC label 3">Python support and heading ID 3python-support.
The tag stripper treats the > inside the quoted attribute as the end of
the tag. The same problem affects HTML in data-toc-label.

Reuse the inline parser's HTML pattern in strip_tags so complete tags are
removed. The heading ID and label become python-support and Python support. Raw heading HTML and HTML entities are preserved.

Regression tests cover single and double quotes, embedded quotes, multiline
attributes, heading IDs, rendered TOC, TOC tokens, and custom labels. All
nine new regression subcases fail on unchanged master and pass with the fix.

Validation on Windows:

  • Python 3.11.16, with tox's Pygments 2.7.1: 1,085 passed, 51 skipped.
  • Python 3.15.0: 1,025 passed, 111 skipped (including Pygments cases).
  • All 65 TOC tests, full Flake8 on Python 3.11, wheel/sdist build, and strict
    Zensical documentation build pass.
  • Compared 214 existing documents and fixtures using extra and toc:
    rendered output, TOC, and tokens are unchanged.

HTML Tidy checks and documentation spellchecking were not run. Other operating systems and the full
upstream CI matrix were not run locally.

AI Assistance Disclosure

  • No AI tools were used in preparing this PR.

  • AI tools were used and I have disclosed which ones, and have fully reviewed and verified their output.

    AI tools were use to assist with the following:

    • Code
    • Code Comments
    • Documentation
    • Changelog Entry
    • Commit Message
    • The Description Above
    • Other: investigation, tests, and validation

Assisted by Codex

Checklist

The TOC tag stripper stops at the first greater-than sign, including one
inside a quoted attribute. Attribute text then enters heading IDs and TOC
labels. Reuse the inline parser's HTML pattern to strip the complete tag
in both heading content and custom labels, preserving HTML entities.

Add regression coverage for both quote styles, embedded quotes, multiline
attributes, generated IDs, TOC tokens, and custom labels.

Assisted by Codex with investigation, implementation, tests, changelog,
validation, and this commit message.

Signed-off-by: Casper Verbuyst <casperverbuyst@gmail.com>
@waylan waylan added the needs-review Needs to be reviewed and/or approved. label Oct 22, 2026
@waylan
waylan merged commit 5e335ef into Python-Markdown:master Oct 22, 2026
14 checks passed
@waylan waylan added approved The pull request is ready to be merged. and removed needs-review Needs to be reviewed and/or approved. labels Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved The pull request is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants