Skip to content

Serialize fenced_code attributes like the serializer when codehilite is off - #1719

Open
jeej3000 wants to merge 2 commits into
Python-Markdown:masterfrom
jeej3000:fix-fenced-code-bool-attrs-serializer
Open

jeej3000 wants to merge 2 commits into
Python-Markdown:masterfrom
jeej3000:fix-fenced-code-bool-attrs-serializer

Conversation

@jeej3000

@jeej3000 jeej3000 commented Nov 18, 2026 •

Copy link
Copy Markdown

Description

Fixes #1713. Replaces #1716, which took the wrong approach (it dropped the attributes). Note that #1718 proposes the same fix.

As @waylan explained in #1713, without codehilite the attributes may be meant for a JS highlighting library and must not be removed. fenced_code bypasses the serializer, so it now reproduces the serializer's handling (#1674) for the values it keeps as Python booleans:

  • None => key
  • True => key if the output format is html and key is in BOOLEAN_ATTRIBUTES['html'], otherwise key="key"
  • False => nothing is output
  • anything else => key="escaped value" as before

Tests cover None/True/False, html and xhtml output, and with and without codehilite (and with and without Pygments). The full test suite passes locally.

I read "value == False => (an empty string)" as the attribute being omitted, not rendered as key="". Please tell me if you meant the latter.

jeej3000 and jeej1k are both my accounts; jeej1k is credited as co-author as a backup in case one account is lost.

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: tests (Claude Code, Claude Sonnet 5.5)

Checklist

🤖 Generated with Claude Code

…is off

Boolean options such as `linenums` set in an `attr_list` raised
`TypeError` when `codehilite` was not enabled. Attributes are passed on
to the output unchanged and serialized the way the serializer does:
`None` as a bare key, `True` as a bare key for HTML boolean attributes in
`html` output and `key="key"` otherwise, and `False` as nothing.

Fixes Python-Markdown#1713.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-authored-by: jeej1k <351634202+jeej1k@users.noreply.github.com>
@waylan

waylan commented Nov 19, 2026

Copy link
Copy Markdown
Member

This needs to be compared to #1718. Both claim to fix #1713.

@waylan waylan added the needs-review Needs to be reviewed and/or approved. label Nov 19, 2026
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-authored-by: jeej1k <351634202+jeej1k@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-review Needs to be reviewed and/or approved.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fenced_code + attr_list: boolean options like linenums crash with "cannot serialize" when codehilite is not enabled

2 participants