Skip to content

Commit 08badb8

Browse files
committed
First working version
0 parents  commit 08badb8

36 files changed

+3462
-0
lines changed

.gitignore

+566
Large diffs are not rendered by default.

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Tim Vink
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

MANIFEST.in

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mkdocs_print_site_plugin/css/*

README.md

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
**This plugin is under development and the first version has not yet been released**
2+
3+
# mkdocs-print-site-plugin
4+
5+
[MkDocs](https://www.mkdocs.org/) plugin that adds a page to your site combining all pages, allowing your site visitors to *File > Print > Save as PDF* the entire site.
6+
7+
## Features :star2:
8+
9+
- Allow visitors to create PDFs from MkDocs sites themselves
10+
- Support for pagination
11+
- Support for generic and [mkdocs-material](https://github.com/squidfunk/mkdocs-material) themes, but works on all themes
12+
- Lightweight, no dependencies
13+
14+
Currently, there is no support for PDF bookmarks. Have a look at alternatives like [mkdocs-pdf-export-plugin]() and [mkdocs-pdf-with-js-plugin](https://github.com/smaxtec/mkdocs-pdf-with-js-plugin).
15+
16+
## Setup
17+
18+
Install the plugin using `pip3`:
19+
20+
```bash
21+
pip3 install mkdocs-print-site-plugin
22+
```
23+
24+
Next, add the following lines to your `mkdocs.yml`:
25+
26+
```yml
27+
plugins:
28+
- search
29+
- print-site
30+
```
31+
32+
> If you have no `plugins` entry in your config file yet, you'll likely also want to add the `search` plugin. MkDocs enables it by default if there is no `plugins` entry set.
33+
34+
35+
## TODO
36+
37+
- Perhaps prevent the write file, by having the .md file be part of the package? Or put it in a tmp folder? See # https://github.com/greenape/mknotebooks/blob/master/mknotebooks/plugin.py#L126
38+
- Add a demo website
39+
- Try to get PDF bookmarks working. Standards: https://www.w3.org/TR/2014/WD-css-gcpm-3-20140513/#bookmarks , lessons https://print-css.rocks/lessons
40+
- Add print button to every page? See approach described at https://github.com/danielfrg/mkdocs-jupyter
41+
- Ensure order of pages is consistent with navigation order, by making sure the plugin has been added last in the list.
42+
- ensure this plugin is defined last (to allow other plugins to make any modifications first). Return a warning if this is not the case.
43+
- Add option to change the print page title.
44+
- Add option to insert a Table of contents page. Here is how to create the leader dots and page numbers using CSS https://www.smashingmagazine.com/2015/01/designing-for-print-with-css/
45+
- Add option to insert a frontcover page http://blog.michaelperrin.fr/2019/11/04/printing-the-web-part-2-html-and-css-for-printing-books/
46+
- Display current chapter title in the footer http://blog.michaelperrin.fr/2019/11/04/printing-the-web-part-2-html-and-css-for-printing-books/
47+
- check if appending print page does not break nested navigations (perhaps unit test?)
48+
- check tables with lots of columns, deal with overflow
49+
- Option to add print url after links? https://css-tricks.com/snippets/css/print-url-after-links/
50+
- support different anchor links, or at least throw warning if different than #
51+
https://www.mkdocs.org/user-guide/writing-your-docs/
52+
```yml
53+
markdown_extensions:
54+
- toc:
55+
permalink: "#"
56+
```
57+
- ensure support of 'use_directory_urls' settings https://www.mkdocs.org/user-guide/configuration/#use_directory_urls
58+
59+
```python
60+
[p.url for p in self.pages]
61+
['index.html', 'z.html', 'a.html']
62+
```
63+
64+
## Contributing
65+
66+
Contributions are very welcome! Start by reading the [contribution guidelines](https://timvink.github.io/mkdocs-print-site-plugin/contributing.html).

docs/contributing.md

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Contribution Guidelines
2+
3+
Thanks for considering to contribute to this project! Some guidelines:
4+
5+
- Go through the issue list and if needed create a relevant issue to discuss the change design. On disagreements, maintainer(s) will have the final word.
6+
- You can expect a response from a maintainer within 7 days. If you haven’t heard anything by then, feel free to ping the thread.
7+
- This package tries to be as simple as possible for the user (hide any complexity from the user). Options are only added when there is clear value to the majority of users.
8+
- When issues or pull requests are not going to be resolved or merged, they should be closed as soon as possible. This is kinder than deciding this after a long period. Our issue tracker should reflect work to be done.
9+
10+
## Unit Tests
11+
12+
Make sure to install an editable version before running tests:
13+
14+
```python
15+
pip install -r tests/test_requirements.txt
16+
pip install -e .
17+
pytest --cov=mkdocs_print_site_plugin --cov-report term-missing tests/
18+
```
19+
20+
If it makes sense, writing tests for your PRs is always appreciated and will help get them merged.
21+
22+
In addition, this project uses [pyflakes](https://pypi.org/project/pyflakes/) for static code checking:
23+
24+
```python
25+
pip install pyflakes
26+
pyflakes tests/ mkdocs_print_site_plugin/
27+
```
28+
29+
## Manual testing
30+
31+
To quickly serve a website with your latest changes to the plugin use the sites in our tests suite. For example:
32+
33+
```python
34+
pip install -r tests/test_requirements.txt
35+
pip install -e .
36+
mkdocs serve -f tests/fixutures/basic/mkdocs.yml
37+
```
38+
39+
Tip: If you use google chrome, you can also view the print version of a page inside the browser [by setting the renderer](https://www.smashingmagazine.com/2018/05/print-stylesheets-in-2018/).
40+
41+
## Code Style
42+
43+
Make sure your code *roughly* follows [PEP-8](https://www.python.org/dev/peps/pep-0008/) and keeps things consistent with the rest of the code. I recommended using [black](https://github.com/psf/black) to automatically format your code.
44+
45+
We use google-style docstrings.
46+
47+
## Documentation
48+
49+
Is in `docs/`. To [deploy the docs](https://www.mkdocs.org/user-guide/deploying-your-docs/), run:
50+
51+
```bash
52+
mkdocs gh-deploy
53+
```

docs/demo_content.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Demo Content
2+
3+
This content is here to demonstrate what it looks like while printing.
4+
5+
Go ahead and visit the [print page](print_site.md) and check it out!
6+
7+
## TODO

docs/index.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# mkdocs-print-page-plugin
2+
3+
[MkDocs](https://www.mkdocs.org/) plugin that adds a page to your site combining all pages, allowing your site visitors to *File > Print > Save as PDF* the entire site.
4+
5+
## Installation
6+
7+
Install the plugin using `pip3`:
8+
9+
```bash
10+
pip3 install mkdocs-print-site-plugin
11+
```
12+
13+
Next, add the following lines to your `mkdocs.yml`:
14+
15+
```yml
16+
plugins:
17+
- search
18+
- print-site
19+
```
20+
21+
> If you have no `plugins` entry in your config file yet, you'll likely also want to add the `search` plugin. MkDocs enables it by default if there is no `plugins` entry set.

docs/options.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Options
2+
3+
You can customize the plugin by setting options in `mkdocs.yml`. For example:
4+
5+
```yml
6+
plugins:
7+
- print-site:
8+
add_to_navigation: false
9+
```
10+
11+
## `add_to_navigation`
12+
13+
Default is `true`. Adds a link 'Print Site' to your site navigation.

mkdocs.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
site_name: mkdocs-print-site-plugin Docs
2+
repo_url: https://github.com/timvink/mkdocs-print-site-plugin
3+
site_url: https://timvink.github.io/mkdocs-print-site-plugin/
4+
site_description: MkDocs Plugin allowing your site visitors to *File > Print > Save as PDF* the entire site.
5+
site_author: Tim Vink
6+
7+
use_directory_urls: false
8+
9+
plugins:
10+
- print-site
11+
- search
12+
13+
nav:
14+
- Home: index.md
15+
- Options: options.md
16+
- Demo Content: demo_content.md
17+
- Contributing: contributing.md
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* print styles for mkdocs material theme
2+
https://github.com/squidfunk/mkdocs-material */
3+
4+
@media print {
5+
6+
}
7+
8+
@page {
9+
10+
size: a4 portrait;
11+
margin: 15mm 10mm 25mm 10mm;
12+
counter-increment: page;
13+
14+
@bottom-center {
15+
content: string(chapter);
16+
}
17+
@bottom-right {
18+
content: 'Page ' counter(page);
19+
}
20+
21+
}
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* Print styles for default MkDocs theme */
2+
3+
@media print {
4+
.col-md-3 { display: none !important; }
5+
}
6+
7+
@page {
8+
9+
size: a4 portrait;
10+
margin: 15mm 10mm 15mm 10mm;
11+
counter-increment: page;
12+
13+
@bottom-center {
14+
content: string(chapter);
15+
}
16+
@bottom-right {
17+
content: 'Page ' counter(page);
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
2+
#print-site-banner {
3+
border:2px;
4+
border-style:solid;
5+
border-color:#000000;
6+
padding: 0em 1em 0em 1em;
7+
margin-bottom: 2em;
8+
}
9+
#print-site-banner h3 {
10+
margin-top: 1rem;
11+
}
12+
13+
14+
@media print {
15+
16+
/* included bookmarks on h1 and h2
17+
Doesn't work, but included In case Chrome gets support
18+
for these experimental CSS features that define PDF bookmarks */
19+
h1 {
20+
bookmark-label: content();
21+
-ah-bookmark-level: 1;
22+
-ro-pdf-bookmark-level: 1;
23+
}
24+
h2 {
25+
bookmark-label: content();
26+
-ah-bookmark-level: 2;
27+
-ro-pdf-bookmark-level: 2;
28+
}
29+
30+
#print-site-banner { display: none; }
31+
32+
/* PDF page breaks on each MkDocs page, except the first one */
33+
section.print-page {
34+
page-break-before: always;
35+
}
36+
section.print-page:first-of-type {
37+
page-break-before: avoid;
38+
}
39+
40+
pre, blockquote {
41+
page-break-inside: avoid;
42+
}
43+
44+
/* Avoid a page break immediately after a heading */
45+
/* Credits https://stackoverflow.com/a/9238898/5525118 */
46+
h1 {
47+
page-break-inside: avoid;
48+
}
49+
h1::after {
50+
content: "";
51+
display: block;
52+
height: 100px;
53+
margin-bottom: -100px;
54+
}
55+
56+
}
57+
58+
@page {
59+
60+
/* Prevent image page overflow */
61+
img { max-width: 500px !important; }
62+
63+
}

0 commit comments

Comments
 (0)