Description
I was upgrading one of my projects from markdown==3.1
to markdown==3.2.1
, and had a very weird behaviour that was quite hard to track down.
In my test case, I had this in my imports:
from markdown import Markdown
from nbconvert import HTMLExporter
def render_markdown(raw):
return markdown_renderer.reset().convert(raw)
def render_ipynb(raw):
exporter = HTMLExporter()
exporter.template_file="basic"
return smartypants(exporter.from_notebook_node(reads(renumber_notebook(raw), 4))[0]
When I called only render_markdown
, I got this pretty obscure exception:
Traceback (most recent call last):
File "markdown_test.py", line 81, in <module>
print(render_markdown(test_block))
File "markdown_test.py", line 79, in render_markdown
return markdown_renderer.reset().convert(raw)
File "/Users/rcarmo/.pyenv/versions/3.6.9/lib/python3.6/site-packages/markdown/core.py", line 269, in convert
newRoot = treeprocessor.run(root)
File "/Users/rcarmo/.pyenv/versions/3.6.9/lib/python3.6/site-packages/markdown/extensions/footnotes.py", line 388, in run
footnotesDiv = self.footnotes.makeFootnotesDiv(root)
File "/Users/rcarmo/.pyenv/versions/3.6.9/lib/python3.6/site-packages/markdown/extensions/footnotes.py", line 181, in makeFootnotesDiv
self.parser.parseChunk(surrogate_parent, self.footnotes[id])
File "/Users/rcarmo/.pyenv/versions/3.6.9/lib/python3.6/site-packages/markdown/blockparser.py", line 105, in parseChunk
self.parseBlocks(parent, text.split('\n\n'))
File "/Users/rcarmo/.pyenv/versions/3.6.9/lib/python3.6/site-packages/markdown/blockparser.py", line 123, in parseBlocks
if processor.run(parent, blocks) is not False:
File "/Users/rcarmo/.pyenv/versions/3.6.9/lib/python3.6/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
make: *** [smoke-test] Error 1
Reverting back to markdown==3.1
"fixed" it, and it took me a long time to figure out what caused it in the first place.
As it turns out, it went away when I removed the nbconvert
import or moved it inside render_ipynb
(which is bad form, but turned out to be the quickest workaround). I assume that nbconvert
does some kind of conflicting initialization to markdown
that does not go away with reset()
...
But since it wasn't happening in markdown==3.1
and happens in both still versions of nbconvert
I've tried (nbconvert==5.5.0
and nbconvert==5.6.1
), I'm assuming something changed in markdown
to cause this issue.