termynal / termynal.py

Python markdown terminal. Built for mkdocs
https://termynal.github.io/termynal.py/
MIT License
85 stars 8 forks source link

Plugin crashes when a raw HTML div with `markdown` attribute is present into Markdown pages #4

Closed Guts closed 1 year ago

Guts commented 1 year ago

Thanks for your markdown processor and Mkdocs plugin.

Trying to use it in my Mdkocs website, the plugin crashes with pages containing not pure Markdown. Typically, I'm using grids from Material for Mkdocs and I was facing this error message during build:

ERROR    -  Error reading page 'team/sponsoring.md': 'xml.etree.ElementTree.Element' object has no attribute 'startswith'
Traceback (most recent call last):
  File "/home/username/Git/Geotribu/website/.venv/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
  File "/home/username/Git/Geotribu/website/.venv/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/username/Git/Geotribu/website/.venv/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/username/Git/Geotribu/website/.venv/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/username/Git/Geotribu/website/.venv/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/username/Git/Geotribu/website/.venv/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/username/Git/Geotribu/website/.venv/lib/python3.10/site-packages/mkdocs/__main__.py", line 234, in serve_command
    serve.serve(dev_addr=dev_addr, livereload=livereload, watch=watch, **kwargs)
  File "/home/username/Git/Geotribu/website/.venv/lib/python3.10/site-packages/mkdocs/commands/serve.py", line 83, in serve
    builder(config)
  File "/home/username/Git/Geotribu/website/.venv/lib/python3.10/site-packages/mkdocs/commands/serve.py", line 76, in builder
    build(config, live_server=live_server, dirty=dirty)
  File "/home/username/Git/Geotribu/website/.venv/lib/python3.10/site-packages/mkdocs/commands/build.py", line 308, in build
    _populate_page(file.page, config, files, dirty)
  File "/home/username/Git/Geotribu/website/.venv/lib/python3.10/site-packages/mkdocs/commands/build.py", line 181, in _populate_page
    page.render(config, files)
  File "/home/username/Git/Geotribu/website/.venv/lib/python3.10/site-packages/mkdocs/structure/pages.py", line 270, in render
    self.content = md.convert(self.markdown)
  File "/home/username/Git/Geotribu/website/.venv/lib/python3.10/site-packages/markdown/core.py", line 261, in convert
    self.lines = prep.run(self.lines)
  File "/home/username/Git/Geotribu/website/.venv/lib/python3.10/site-packages/termynal/markdown.py", line 46, in run
    lines_by_placeholder = self._get_lines(lines, content_by_placeholder)
  File "/home/username/Git/Geotribu/website/.venv/lib/python3.10/site-packages/termynal/markdown.py", line 64, in _get_lines
    if content.startswith(self.comment):
AttributeError: 'xml.etree.ElementTree.Element' object has no attribute 'startswith'

Note that it's a kind of conflict with Markdown in HTML extension.

I've used the reproduction method from Material for Mkdocs to provide a reproductible example:

example.zip

PR is coming.

daxartio commented 1 year ago

Fixed in 0.3.1

I hope it works

Guts commented 1 year ago

Thanks!

It does: check of a mkdocs build and generated site

It still have some glitches (no animated input) but I'll look into deeper later.