Skip to content

Fix boolean fenced code attributes without codehilite - #1718

Merged
waylan merged 4 commits into
Python-Markdown:masterfrom
ARAYN7011:fix-fenced-code-bool-attrs-1713
Nov 27, 2026
Merged

waylan merged 4 commits into
Python-Markdown:masterfrom
ARAYN7011:fix-fenced-code-bool-attrs-1713

Conversation

@ARAYN7011

Copy link
Copy Markdown
Contributor

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

@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
Contributor 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.

@ARAYN7011
ARAYN7011 force-pushed the fix-fenced-code-bool-attrs-1713 branch from f229286 to 3143b71 Compare November 25, 2026 12:41
@waylan

waylan commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Both fixes are essentially the same and either would be fine. However, neither includes comprehensive tests which cover every possible scenario. That said, #1719 includes more comprehensive tests that this does.

@waylan waylan added requires-changes Awaiting updates after a review. and removed needs-review Needs to be reviewed and/or approved. labels Nov 25, 2026
@ARAYN7011
ARAYN7011 force-pushed the fix-fenced-code-bool-attrs-1713 branch from 3143b71 to 7e72636 Compare November 25, 2026 14:32
@ARAYN7011

Copy link
Copy Markdown
Contributor Author

Thanks @waylan. I rebased onto current master (changelog conflict) and added tests for: html output format, a valueless attribute, and mixed boolean/string/escaped values (7e72636). The full suite passes (1233 tests). If you'd rather take #1719, that's fine with me.

@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.

That's a good start. However, that only tests output_format=xhtml. We would need the same set of tests with output_format=html as well.

@ARAYN7011
ARAYN7011 force-pushed the fix-fenced-code-bool-attrs-1713 branch from 7e72636 to a842673 Compare November 26, 2026 04:47
@ARAYN7011

Copy link
Copy Markdown
Contributor Author

Thanks @waylan. You're right that nowrap=false was misleading: nowrap isn't one of the parsed boolean options, so it stayed a plain string. I replaced it with guess_lang=false (a real boolean option) in the mixed test, so false is dropped consistently. I also added output_format=html (and explicit xhtml) variants of the boolean, false-boolean, valueless and mixed tests (a842673, rebased onto current master; full suite passes).

Comment thread docs/changelog.md Resolved
ARAYN7011 and others added 4 commits November 27, 2026 10:18
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>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@ARAYN7011
ARAYN7011 force-pushed the fix-fenced-code-bool-attrs-1713 branch from a842673 to 48a3f60 Compare November 27, 2026 04:48
@ARAYN7011

Copy link
Copy Markdown
Contributor Author

Thanks @waylan. Rebased onto current master and moved the changelog entry into the new Unreleased section (48a3f60). Full suite passes (1242 tests).

@waylan
waylan merged commit 6c359af into Python-Markdown:master Nov 27, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

requires-changes Awaiting updates after a review.

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