diff --git a/README.md b/README.md index 602c059..208b1cc 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ What makes this plugin particular, is that: 1. Your documentation is exported as a single PDF file 1. The order of pages fits the navigation as defined in the MkDocs configuration file 1. The ability to override the default design to make it fit your needs +1. The ability to exclude some files from the generated PDF 1. No layout issues 1. No conflict with the theme design 1. Table of contents integrated in the PDF diff --git a/docs/getting-started.md b/docs/getting-started.md index 4108e56..9fefd6f 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -6,6 +6,8 @@ Before installing [MkDocs][1], you need to make sure you have Python and `pip` – the Python package manager – up and running. You can verify if you're already good to go with the following commands: +[1]: https://www.mkdocs.org + ``` sh python --version # Python 3.6.7 @@ -57,5 +59,21 @@ plugins: - toc_title: ToC ``` +### Hide file content from the generated PDF +Sometime it can be interesting to hide a given documentation file from the PDF. + +This can be achieved by using the [Mkdocs YAML Style Meta-Data](https://www.mkdocs.org/user-guide/writing-your-docs/#yaml-style-meta-data) features. + +For this, define a `pdf` metadata and set it to `False` in the top of your Markdown file like in the following example. + +``` markdown +--- +pdf: False +--- + +#Page title + +``` + ### Documentation design You have the ability to design the layout of your Generated PDF by using CSS. You can find out complete documentation by visiting our [Layout customisation](layout-design.md) section. diff --git a/docs/release-notes.md b/docs/release-notes.md index 096b4c5..9632ffa 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -19,6 +19,7 @@ pip show mkpdfs-mkdocs * The plugin was breaking the documentation generation (#1). Now if the theme is not compatible, the PDF version of the documentation won't be created and a warning will be displayed without breaking the documentation generation. * Enhance the view by adding a section page in the documentation (#2) +* Added the ability to remove the inclusion of some Markdown files in the generated pdf (#3) ### 1.0.0 - April 15, 2019 diff --git a/mkpdfs_mkdocs/generator.py b/mkpdfs_mkdocs/generator.py index 5d7b755..ae7573b 100644 --- a/mkpdfs_mkdocs/generator.py +++ b/mkpdfs_mkdocs/generator.py @@ -66,6 +66,10 @@ def add_nav(self, nav): self.addToOrder(p) def addToOrder(self, page): + if page.is_page and page.meta != None and 'pdf' in page.meta and page.meta['pdf'] == False: + print(page.meta) + exit(1) + return; if page.is_page : self._page_order.append(page.file.url) else : @@ -86,6 +90,10 @@ def addToOrder(self, page): self.addToOrder(child) + def remove_from_order(self, item): + + return + def add_article(self, content, page, base_url): if not self.generate: return None @@ -106,6 +114,9 @@ def add_article(self, content, page, base_url): span = soup.new_tag('span') span['id'] = 'mkpdf-{}'.format(url) article.insert(0, span) + if page.meta != None and 'pdf' in page.meta and page.meta['pdf'] == False: + # print(page.meta) + return self.get_path_to_pdf(page.file.dest_path) self._articles[page.file.url] = article return self.get_path_to_pdf(page.file.dest_path) @@ -130,6 +141,9 @@ def add_tocs(self): self._toc = self.html.new_tag('article', id='contents') self._toc.insert(0, title) for n in self.nav: + if n.is_page and n.meta != None and 'pdf' in n.meta \ + and n.meta['pdf'] == False: + continue h3 = self.html.new_tag('h3') h3.insert(0, n.title) self._toc.append(h3) @@ -153,7 +167,8 @@ def gen_articles (self): if self.config['toc_position'] == 'pre' : self.add_tocs() for url in self._page_order: - self.html.body.append(self._articles[url]) + if url in self._articles: + self.html.body.append(self._articles[url]) if self.config['toc_position'] == 'post' : self.add_tocs() @@ -165,6 +180,9 @@ def get_path_to_pdf(self, start): def _gen_toc_section(self, section): for p in section.children: + if p.is_page and p.meta != None and 'pdf' \ + in p.meta and p.meta['pdf'] == False: + continue stoc = self._gen_toc_for_section(p.file.url, p) child = self.html.new_tag('div') child.append(stoc)