Skip to content

Fix toc crash on a heading with a valueless data-toc-label - #1714

Merged
waylan merged 1 commit into
Python-Markdown:masterfrom
mccalpink:fix/1712-valueless-toc-label
Nov 17, 2026
Merged

waylan merged 1 commit into
Python-Markdown:masterfrom
mccalpink:fix/1712-valueless-toc-label

Conversation

@mccalpink

Copy link
Copy Markdown
Contributor

Description

Fixes #1712.

data-toc-label without a value is now treated as absent (same as id in #1706): the TOC name is taken from the heading text and the attribute is removed. An explicit empty data-toc-label="" still produces an empty name, so the check is specifically for None.

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: code review by Claude Code (Claude Opus)

    Tool: Claude Code (Anthropic; Claude Sonnet wrote the fix, tests, code comments, changelog entry and commit message; Claude Opus reviewed them).

    I reviewed every change. I wrote the description above myself, from notes Claude Code prepared.

Checklist

The `attr_list` extension writes a bare attribute with a value of
None, so `{: data-toc-label }` reached `unescape(None)` and raised
`TypeError`. A valueless label is now treated like a missing one: the
heading text is used as the TOC name and the attribute is removed, as
Python-Markdown#1706 did for a valueless `id`.

The check is `is not None` rather than a falsy test so that an explicit
`data-toc-label=""` still gives an empty name, as before.

Fixes Python-Markdown#1712.

@waylan waylan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this.

@waylan waylan mentioned this pull request Nov 17, 2026
12 of 15 tasks
@waylan
waylan merged commit 2c96e36 into Python-Markdown:master Nov 17, 2026
14 checks passed
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.

toc + attr_list: valueless {: data-toc-label } crashes with TypeError (regression in 3.11.3)

2 participants