Skip to content

PrettifyTreeprocessor AttributeError #1261

@fourpoints

Description

@fourpoints

This code section near the bottom of markdown.treeprocessors raises AttributeError if pre[0].text is None.

# Clean up extra empty lines at end of code blocks.
pres = root.iter('pre')
for pre in pres:
    if len(pre) and pre[0].tag == 'code':
        pre[0].text = util.AtomicString(pre[0].text.rstrip() + '\n')

The check should be if len(pre) and pre[0].tag == 'code' and pre[0].text is not None or isinstance(pre[0].text, str), but that may be too strict.


I encountered this with a custom Block/Inline processor. The band-aid fix was just to ensure these elements had text.

for pre in root.iter("pre"):
    if pre[0].text is None:
        pre[0].text = ""

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugBug report.confirmedConfirmed bug report or approved feature request.coreRelated to the core parser code.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions