onixpro / mkdocs-drawio-file

Embeding files of Diagrams.net (Draw.io) into MkDocs
19 stars 5 forks source link

plugin tries to process file page-2.drawio.png #7

Open JuergenKosel opened 1 year ago

JuergenKosel commented 1 year ago

Hello,

after installing the plugin mkdocs-pdf-export-plugin with

pip install mkdocs-pdf-export-plugin

mkdocs fails on a markdown file which contains this line:

![page-2](page-2.drawio.png)

with the following output:

ERROR    -  Error building page 'environment/general.md': Start tag expected, '<' not found, line 1, column 1 (page-2.drawio.drawio.png, line 1)
Traceback (most recent call last):
  File "/usr/local/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.9/dist-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.9/dist-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.9/dist-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.9/dist-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/mkdocs/__main__.py", line 250, in build_command
    build.build(cfg, dirty=not clean)
  File "/usr/local/lib/python3.9/dist-packages/mkdocs/commands/build.py", line 329, in build
    _build_page(file.page, config, doc_files, nav, env, dirty)
  File "/usr/local/lib/python3.9/dist-packages/mkdocs/commands/build.py", line 234, in _build_page
    output = config.plugins.run_event('post_page', output, page=page, config=config)
  File "/usr/local/lib/python3.9/dist-packages/mkdocs/plugins.py", line 520, in run_event
    result = method(item, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/mkdocs_drawio_file/plugin.py", line 56, in on_post_page
    diagram.replace_with(BeautifulSoup(self.substitute_image(path, diagram['src'], diagram['alt']), 'html.parser'))
  File "/usr/local/lib/python3.9/dist-packages/mkdocs_drawio_file/plugin.py", line 64, in substitute_image
    diagram_xml = etree.parse(os.path.join(path, src))
  File "src/lxml/etree.pyx", line 3541, in lxml.etree.parse
  File "src/lxml/parser.pxi", line 1879, in lxml.etree._parseDocument
  File "src/lxml/parser.pxi", line 1905, in lxml.etree._parseDocumentFromURL
  File "src/lxml/parser.pxi", line 1808, in lxml.etree._parseDocFromFile
  File "src/lxml/parser.pxi", line 1180, in lxml.etree._BaseParser._parseDocFromFile
  File "src/lxml/parser.pxi", line 618, in lxml.etree._ParserContext._handleParseResultDoc
  File "src/lxml/parser.pxi", line 728, in lxml.etree._handleParseResult
  File "src/lxml/parser.pxi", line 657, in lxml.etree._raiseParseError
  File "/home/klj/development-process/docs/environment/page-2.drawio.drawio.png", line 1
lxml.etree.XMLSyntaxError: Start tag expected, '<' not found, line 1, column 1

After removing the mkdocs-pdf-export-plugin, mkdocs succeeds. So this is an icompatibility issue with https://github.com/zhaoterryy/mkdocs-pdf-export-plugin

JuergenKosel commented 1 year ago

To be more precise: It is enough to install the mkdocs-pdf-export-plugin. Even if the plugin is disabled in mkdocs.yml the problem occurs.

JuergenKosel commented 1 year ago

The issue is unrelated to the mkdocs-pdf-export-plugin - it is a regression!

My docker image without the mkdocs-pdf-export-plugin used an older version (1.3.0) of the drawio-file plugin than my new created docker image with the additional plugin. (Uses 1.5.2)

tuunit commented 1 year ago

Indeed the issue is with the current regex pattern, as it is not matching for the end of the filename but for any name containing ".drawio". I'll raise a PR to fix this issue tomorrow.

https://github.com/onixpro/mkdocs-drawio-file/blob/c547793f1338f2120ac48722b2eeed5bb3181d91/mkdocs_drawio_file/plugin.py#L43-L45

JuergenKosel commented 1 year ago

I have added a gitlab project to check this issue: https://gitlab.com/juergen.kosel.jk/gitlab-pages-with-mkdocs/-/commits/check-drawio-regex-issue

tuunit commented 1 year ago

Should be resolved with #8 Waiting for merge and deployment of new version.