Skip to content

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

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

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

@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 needs-review Needs to be reviewed and/or approved. requires-changes Awaiting updates after a review. and removed needs-review Needs to be reviewed and/or approved. labels Nov 19, 2026
jeej3000 and others added 2 commits November 25, 2026 18:05
…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>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-authored-by: jeej1k <351634202+jeej1k@users.noreply.github.com>
@jeej3000
jeej3000 force-pushed the fix-fenced-code-bool-attrs-serializer branch from c4863ca to 354f0aa Compare November 25, 2026 17:08
@waylan

waylan commented Nov 27, 2026

Copy link
Copy Markdown
Member

This is being closed in favor of #1718. Both provide the same fix, but #1718 provided the tests in the format we requested.

@waylan waylan closed this Nov 27, 2026
@waylan waylan added duplicate The issue has been previously reported. rejected The pull request is rejected for the stated reasons. and removed requires-changes Awaiting updates after a review. labels Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate The issue has been previously reported. rejected The pull request is rejected for the stated reasons.

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