ThomasTNO / mkdocs-pdf

This plugin allows you to embed PDFs in your documentation using standard Markdown syntax.
MIT License
7 stars 2 forks source link

lxml.etree.ParserError: Document is empty #3

Closed vascowhite closed 5 months ago

vascowhite commented 5 months ago

I have installed your plugin using the instructions you give, however it always causes an error.

I am using mkdocs version 1.5.3

Here is the list of packages installed into the venv:

Package                    Version
-------------------------- -----------
astroid                    3.1.0
Babel                      2.14.0
beautifulsoup4             4.12.3
certifi                    2024.2.2
charset-normalizer         3.3.2
click                      8.1.7
colorama                   0.4.6
csscompressor              0.9.5
dill                       0.3.8
fontawesome-markdown       0.2.6
ghp-import                 2.1.0
greenlet                   3.0.3
htmlmin2                   0.1.13
idna                       3.7
isort                      5.13.2
Jinja2                     3.1.3
jsmin                      3.0.1
lxml                       5.2.1
Markdown                   3.6
markdown-katex             202112.1034
MarkupSafe                 2.1.5
mccabe                     0.7.0
mergedeep                  1.3.4
mkdocs                     1.5.3
mkdocs-material            9.5.18
mkdocs-material-extensions 1.3.1
mkdocs-minify-plugin       0.8.0
mkdocs-pdf                 0.1.1
msgpack                    1.0.8
packaging                  24.0
paginate                   0.5.6
pathlib2                   2.3.7.post1
pathspec                   0.12.1
pip                        23.2.1
platformdirs               4.2.0
Pygments                   2.17.2
pylint                     3.1.0
pymdown-extensions         10.8
pynvim                     0.5.0
python-dateutil            2.9.0.post0
PyYAML                     6.0.1
pyyaml_env_tag             0.1
regex                      2024.4.16
requests                   2.31.0
setuptools                 69.5.1
six                        1.16.0
soupsieve                  2.5
tomlkit                    0.12.4
urllib3                    2.2.1
watchdog                   4.0.0
wheel                      0.41.2

The error code is shown below

mkdocs serve
INFO    -  Building documentation...
INFO    -  Cleaning site directory
ERROR   -  Error reading page 'smm/overview.md': Document is empty
Traceback (most recent call last):
  File "/home/paul/.local/share/virtualenvs/documentation-fyA92iNJ/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/home/paul/.local/share/virtualenvs/documentation-fyA92iNJ/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/paul/.local/share/virtualenvs/documentation-fyA92iNJ/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/home/paul/.local/share/virtualenvs/documentation-fyA92iNJ/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/paul/.local/share/virtualenvs/documentation-fyA92iNJ/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/paul/.local/share/virtualenvs/documentation-fyA92iNJ/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/paul/.local/share/virtualenvs/documentation-fyA92iNJ/lib/python3.11/site-packages/mkdocs/__main__.py", line 270, in serve_command
    serve.serve(**kwargs)
  File "/home/paul/.local/share/virtualenvs/documentation-fyA92iNJ/lib/python3.11/site-packages/mkdocs/commands/serve.py", line 86, in serve
    builder(config)
  File "/home/paul/.local/share/virtualenvs/documentation-fyA92iNJ/lib/python3.11/site-packages/mkdocs/commands/serve.py", line 67, in builder
    build(config, live_server=None if is_clean else server, dirty=is_dirty)
  File "/home/paul/.local/share/virtualenvs/documentation-fyA92iNJ/lib/python3.11/site-packages/mkdocs/commands/build.py", line 322, in build
    _populate_page(file.page, config, files, dirty)
  File "/home/paul/.local/share/virtualenvs/documentation-fyA92iNJ/lib/python3.11/site-packages/mkdocs/commands/build.py", line 179, in _populate_page
    page.content = config.plugins.on_page_content(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/paul/.local/share/virtualenvs/documentation-fyA92iNJ/lib/python3.11/site-packages/mkdocs/plugins.py", line 578, in on_page_content
    return self.run_event('page_content', html, page=page, config=config, files=files)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/paul/.local/share/virtualenvs/documentation-fyA92iNJ/lib/python3.11/site-packages/mkdocs/plugins.py", line 507, in run_event
    result = method(item, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/paul/.local/share/virtualenvs/documentation-fyA92iNJ/lib/python3.11/site-packages/mkdocs_pdf/plugin.py", line 11, in on_page_content
    content = fromstring(html)
              ^^^^^^^^^^^^^^^^
  File "/home/paul/.local/share/virtualenvs/documentation-fyA92iNJ/lib/python3.11/site-packages/lxml/html/__init__.py", line 850, in fromstring
    doc = document_fromstring(html, parser=parser, base_url=base_url, **kw)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/paul/.local/share/virtualenvs/documentation-fyA92iNJ/lib/python3.11/site-packages/lxml/html/__init__.py", line 738, in document_fromstring
    raise etree.ParserError(
lxml.etree.ParserError: Document is empty

Do you have any suggestions as to what could be going wrong?

ThomasTNO commented 5 months ago

Hi @vascowhite,

Thanks for your report. In order to reproduce. Could you tell me whether "smm/overview.md" is an empty markdown file?

Possibly we need to handle the empty page as an edge case.

vascowhite commented 5 months ago

Yes, you are correct, that is an empty document and the plugin works when I put some content into it.

Thanks for the quick reply.

ThomasTNO commented 5 months ago

Fixed in #4