You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fenced_code + attr_list: boolean options like linenums crash with "cannot serialize" when codehilite is not enabled #1713
With codehilite also enabled, all of these work fine.
From what I can tell, handle_attrs() runs every key in bool_options (linenums, guess_lang, noclasses, use_pygments) through parseBoolValue(), so the config value becomes True, False or None. When Pygments isn't used, those values are written straight into the <code> tag:
f' {sanitize_name(k)}="{_escape_attrib_html(v)}"'
and _escape_attrib_html() only handles strings.
I'm not sure which output you'd prefer (drop the codehilite-only options, or write them as strings), but it probably shouldn't raise. This isn't new: 3.11.2 crashes the same way.
Versions: Markdown 3.11.3 and master (4177c1b), Python 3.14.2, Windows 11.
If attributes are defined for a code block and codehilite is not enabled, then we should assume that the user is passing attributes to a Javascript highlighting library. We do not want to remove or alter those attributes differently than normal attr_list behavior.
The problem is that the extension is not using the serializer, which properly handles these values . Therefore, these should be treated in the same manner as the serializer would handle them (as implemented in #1674). We will need to reimplement the same behavior within the fenced_code extension as outlined below:
value == None => key
value == True and output_format == 'html' and key in markdown.serializers.BOOLEAN_ATTRIBUTES['html'] => key
value == True => key="key"
value == False => (an empty string)
By way of explanation, the default behavior for the attr_list extension is to use key=key internally for truthy values. However, that doesn't preserve explicitly defined falsey values. Therefore, within the fenced_code extension we are preserving boolean values so that they can be passed on to codehilite. However, when codehilite is not enabled, we now need to revert to normal behavior in our x/html output.
Activity
waylan commentedon Nov 17, 2026
If attributes are defined for a code block and
codehiliteis not enabled, then we should assume that the user is passing attributes to a Javascript highlighting library. We do not want to remove or alter those attributes differently than normal attr_list behavior.The problem is that the extension is not using the serializer, which properly handles these values . Therefore, these should be treated in the same manner as the serializer would handle them (as implemented in #1674). We will need to reimplement the same behavior within the fenced_code extension as outlined below:
value == None=>keyvalue == True and output_format == 'html' and key in markdown.serializers.BOOLEAN_ATTRIBUTES['html']=>keyvalue == True=>key="key"value == False=> (an empty string)By way of explanation, the default behavior for the attr_list extension is to use
key=keyinternally for truthy values. However, that doesn't preserve explicitly defined falsey values. Therefore, within the fenced_code extension we are preserving boolean values so that they can be passed on to codehilite. However, when codehilite is not enabled, we now need to revert to normal behavior in our x/html output.Serialize boolean fenced code attributes without codehilite
Serialize boolean fenced code attributes without codehilite
Serialize boolean fenced code attributes without codehilite
Serialize fenced_code attributes like the serializer when codehilite …