Skip to content

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

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

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

Conversation

@jeej3000

Copy link
Copy Markdown

Fixes #1713. Replaces #1716, which took the wrong approach (it dropped the attributes).

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 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. Changelog entry added. Full test suite passes locally.

One point I'd like confirmed: I read "value == False => (an empty string)" as the attribute being omitted entirely, not rendered as key="". Easy to change if you meant the latter.

AI disclosure: Claude Code (Claude Sonnet 5.5) wrote the code change, tests, changelog entry, commit message and this description. I reviewed them and can explain every change.

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

🤖 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
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