zhaoterryy / mkdocs-pdf-export-plugin

An MkDocs plugin to export content pages as PDF files
MIT License
319 stars 42 forks source link

Add support of Admonition #82

Open Kanaduchi opened 4 years ago

Kanaduchi commented 4 years ago

Is it possible to add support of https://python-markdown.github.io/extensions/admonition/ extension?

Currently when I try to export such pages I got an error:

Traceback (most recent call last):
  File "/home/docs/.pyenv/versions/3.7.3/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/docs/.pyenv/versions/3.7.3/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/docs/checkouts/readthedocs.org/user_builds/mqb/envs/newstructure/lib/python3.7/site-packages/mkdocs/__main__.py", line 202, in <module>
    cli()
  File "/home/docs/checkouts/readthedocs.org/user_builds/mqb/envs/newstructure/lib/python3.7/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/docs/checkouts/readthedocs.org/user_builds/mqb/envs/newstructure/lib/python3.7/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/docs/checkouts/readthedocs.org/user_builds/mqb/envs/newstructure/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/docs/checkouts/readthedocs.org/user_builds/mqb/envs/newstructure/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/docs/checkouts/readthedocs.org/user_builds/mqb/envs/newstructure/lib/python3.7/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/docs/checkouts/readthedocs.org/user_builds/mqb/envs/newstructure/lib/python3.7/site-packages/mkdocs/__main__.py", line 163, in build_command
    ), dirty=not clean)
  File "/home/docs/checkouts/readthedocs.org/user_builds/mqb/envs/newstructure/lib/python3.7/site-packages/mkdocs/commands/build.py", line 298, in build
    config['plugins'].run_event('post_build', config)
  File "/home/docs/checkouts/readthedocs.org/user_builds/mqb/envs/newstructure/lib/python3.7/site-packages/mkdocs/plugins.py", line 94, in run_event
    result = method(item, **kwargs)
  File "/home/docs/checkouts/readthedocs.org/user_builds/mqb/envs/newstructure/lib/python3.7/site-packages/mkdocs_pdf_export_plugin/plugin.py", line 120, in on_post_build
    self.renderer.write_combined_pdf(abs_pdf_path)
  File "/home/docs/checkouts/readthedocs.org/user_builds/mqb/envs/newstructure/lib/python3.7/site-packages/mkdocs_pdf_export_plugin/renderer.py", line 50, in write_combined_pdf
    render = self.render_doc(p[0], p[1], p[2])
TypeError: 'NoneType' object is not subscriptable
rocinante333 commented 4 years ago

I am able to export without issue; however, the icons used with Admonition are converted to soild color squares.

image

theanurin commented 3 years ago

I am able to export without issue; however, the icons used with Admonition are converted to soild color squares.

image

I have same experience, but in my case generated PDF has empty page before current page. May be related to #89

estan commented 2 years ago

@rocinante333 @theanurin I found that admonitions used to look correct (including icon, and with correct border look) in mkdocs-material 4.6.3 but broke with mkdocs-material 5.0.0 (first bad commit is b345a0b65) and filed this mkdocs-material issue about it: https://github.com/squidfunk/mkdocs-material/issues/3771

I'm not sure if the solution is some change in mkdocs-material or if mkdocs-pdf-export-plugin or weasyprint needs to do something to "catch up" to handle the changes in mkdocs-material, but let's see what mkdocs-material maintainer says.

estan commented 2 years ago

So mkdocs-material author closed the issue saying they don't officially support mkdocs-pdf-export-plugin.

@zhaoterryy Perhaps my investigation in https://github.com/squidfunk/mkdocs-material/issues/3771 can still be of use. It shows that mkdocs-material b345a0b65 Prototyped material icon SVG integration was the first revision of mkdocs-material where mkdocs-pdf-export-plugin started having problem with the admonitions (render them incorrectly).

estan commented 2 years ago

Turns out the missing icon is due to lack of support for image-mask in WeasyPrint (https://github.com/Kozea/WeasyPrint/issues/1458). mkdocs-materials is using this since version 5.