Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Footnotes module regression? #1230

Closed
npcole opened this issue Mar 8, 2022 · 3 comments
Closed

Footnotes module regression? #1230

npcole opened this issue Mar 8, 2022 · 3 comments

Comments

@npcole
Copy link

npcole commented Mar 8, 2022

I've got a strange bug while using markdown as part of a flask app.

The following code works fine when running in the terminal:

import markdown
import markdown.extensions

value = """


This is a test.[^1]

[^1]: this is a footnote.

"""

result = markdown.markdown(value,
              extensions=[
                      'markdown.extensions.footnotes',
                      'markdown.extensions.tables',
                      'markdown.extensions.sane_lists',
                  ]
          )
print(result)

But when run as part of a Flask app I get the following error:

  File "/Users/nicholas/projects/quill/venv3.7/lib/python3.7/site-packages/markdown/core.py", line 388, in markdown
    return md.convert(text)
  File "/Users/nicholas/projects/quill/venv3.7/lib/python3.7/site-packages/markdown/core.py", line 269, in convert
    newRoot = treeprocessor.run(root)
  File "/Users/nicholas/projects/quill/venv3.7/lib/python3.7/site-packages/markdown/extensions/footnotes.py", line 388, in run
    footnotesDiv = self.footnotes.makeFootnotesDiv(root)
  File "/Users/nicholas/projects/quill/venv3.7/lib/python3.7/site-packages/markdown/extensions/footnotes.py", line 181, in makeFootnotesDiv
    self.parser.parseChunk(surrogate_parent, self.footnotes[id])
  File "/Users/nicholas/projects/quill/venv3.7/lib/python3.7/site-packages/markdown/blockparser.py", line 105, in parseChunk
    self.parseBlocks(parent, text.split('\n\n'))
  File "/Users/nicholas/projects/quill/venv3.7/lib/python3.7/site-packages/markdown/blockparser.py", line 123, in parseBlocks
    if processor.run(parent, blocks) is not False:
  File "/Users/nicholas/projects/quill/venv3.7/lib/python3.7/site-packages/markdown/blockprocessors.py", line 591, in run
    p = etree.SubElement(parent, 'p')
TypeError: SubElement() argument 1 must be xml.etree.ElementTree.Element, not Element

If I downgrade to markdown version 3.1, everything works as expected, but upgrading to anything after 3.2 triggers the exception.

Does anyone know what might be going on?

@mitya57
Copy link
Collaborator

mitya57 commented Mar 8, 2022

I think it's the same issue as #950. Please read the discussion there. Changing the order of your imports might fix it.

@npcole
Copy link
Author

npcole commented Mar 8, 2022

Thank you, you are quite right. Putting the line

from defusedxml import ElementTree

right at the start of the application did fix this error. defusedxml really shouldn't behave in that way! Mutter mutter mutter!

@npcole npcole closed this as completed Mar 8, 2022
@waylan
Copy link
Member

waylan commented Mar 8, 2022

Supposedly, this was fixed this in tiran/defusedxml#60 and tiran/defusedxml#63. According to their changelog, those changes should be available in difusedxml 0.8.0, whenever that is released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants