zhaoterryy / mkdocs-pdf-export-plugin

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

CSS for output hardcoded in theme_name.py #22

Closed eloops closed 5 years ago

eloops commented 5 years ago

Looking at the theme files, it looks like the CSS is hardcoded in there and there is no way to override it.

As most of the mkdocs CSS usually resides in ~/css/ it would be nice to be able to drop a CSS file in there and have it pick it up.

ie ~/css/mkdocs-pdf-material.css or something.

eloops commented 5 years ago

Okay, nevermind. I thought I had tested this and it hadn't worked. I placed a file with the CSS (as listed in readme.md) under ~/css and included it in the mkdocs.yml (extra_css section). Upon building the PDF's had the required styling.

shauser commented 5 years ago

I could add an option to disable the inclusion of the stylesheet though, which would help with its customization. The first version actually had you include the stylesheet in your code, but I wanted this to require no changes in user code. This would prevent any requirements for !important or very specific selectors.

eloops commented 5 years ago

I don't really understand your meaning here. Does the hardcoded stylesheet in material.py override the CSS in mkdocs?

I think the only loss from having an external CSS is the inability to add computed values to headers/footers (i.e. page numbers).

shauser commented 5 years ago

The stylesheet is always included as the last stylesheet in the head, so if you want to override any of the options from the default stylesheet you need to have the selector more specific or use !important. Not sure the option would be worth it though, given the very simple workaround if you actually need to overwrite something.

eloops commented 5 years ago

Got it. Thanks for the great plugin! On an unrelated note, I've been trying to make a combined PDF that contains a bookmark/outline tree that mirrors the layout of mkdocs.yml.

zhaoterryy has a pretty good solution (as weasyprint allows to 'build' a PDF logically from code), but unfortunately because of how weasyprint allocates the bookmarks, the resulting outline tree is a mess.

It uses the header level tags to create the outlines, and when collating the individual pages together it makes a mess. I've managed to cobble something together myself (ripping code from mkdocs-pandoc and using PyPDF2), but it is far from ideal or elegant.

I know this should probably be its own issue, though I don't see any really good answers to making it work.