Skip to content

Fix boolean fenced code attributes without codehilite - #1718

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

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

Conversation

@ARAYN7011

Copy link
Copy Markdown

Description

Fixes #1713. When fenced_code and attr_list are enabled but codehilite is not, boolean options such as linenums=true were passed to _escape_attrib_html as bool objects, raising TypeError: cannot serialize True. Following the plan in the issue thread, values are now serialized as the serializer would: None -> key; True -> bare key for HTML boolean attributes with html output, otherwise key="key"; False -> omitted.

Test plan: added two tests in tests/test_syntax/extensions/test_fenced_code.py (fail before, pass after); full python -m unittest discover tests passes; flake8 clean on changed files.

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)

Checklist

Boolean options (e.g. linenums) set via attr_list were passed to the
escape helper as bool objects, raising TypeError when codehilite is not
enabled. Serialize them the way the serializer does.

Fixes Python-Markdown#1713.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@waylan

waylan commented Nov 19, 2026

Copy link
Copy Markdown
Member

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

@waylan waylan added the needs-review Needs to be reviewed and/or approved. label Nov 19, 2026
@ARAYN7011

Copy link
Copy Markdown
Author

Thanks @waylan. For comparison: #1719 is essentially the same fix (a helper that serializes None/True/False like the serializer, using BOOLEAN_ATTRIBUTES for the html output format), so the output should be equivalent. This PR was opened first (2026-11-18 05:53 UTC) and sanitize_name is applied once inside the helper. Either is fine with me; I'm happy to adjust this one to match any preference, or close it if you'd rather take #1719.

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