Skip to content

Fix TypeError for codehilite options in fenced_code attr_list - #1716

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

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

Conversation

@jeej3000

Copy link
Copy Markdown

Description

Fixes #1713.

With fenced_code and attr_list enabled but codehilite not enabled, options such as linenums, guess_lang, noclasses or hl_lines on a fenced block are parsed into True/False/None/list values and then written into the <code> tag, which raises TypeError: cannot serialize None.

This PR omits non-string values from the emitted attributes, the same way use_pygments is already omitted, since those options only apply to codehilite. A test (four variants) and a changelog entry are included; the test fails without the fix.

I chose "omit" over "write as strings" because these options have no meaning as HTML attributes. If you would prefer the string form, I'm happy to change it.

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: Claude Code (Claude Sonnet 5.5) was used for reproducing the bug, the fix and the test. I reviewed and ran everything myself.

Checklist

Options such as `linenums` or `hl_lines` set in the attr_list of a fenced
block are parsed into bool/None/list values. Without `codehilite` they were
written into the `<code>` tag as attributes and crashed serialization.
Omit non-string values from the output, like `use_pygments` already is.

Fixes Python-Markdown#1713.

Co-authored-by: jeej1k <351634202+jeej1k@users.noreply.github.com>
@waylan

waylan commented Nov 17, 2026

Copy link
Copy Markdown
Member

We should not assume that the attributes are not needed in the output when codehilite is disabled. See my comment on #1713 for the appropriate fix for this.

@waylan waylan closed this Nov 17, 2026
@waylan waylan added the rejected The pull request is rejected for the stated reasons. label Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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