├── .gitignore ├── CHANGES ├── LICENSE ├── README.md ├── _config.yml ├── install-macos.command ├── mkdocs_combine ├── __init__.py ├── cli │ ├── __init__.py │ └── mkdocscombine.py ├── exceptions.py ├── filters │ ├── __init__.py │ ├── admonitions.py │ ├── anchors.py │ ├── chapterhead.py │ ├── exclude.py │ ├── headlevels.py │ ├── images.py │ ├── include.py │ ├── math.py │ ├── metadata.py │ ├── tables.py │ ├── toc.py │ └── xref.py └── mkdocs_combiner.py ├── py-requirements.txt └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Mac OS X internals 2 | *.DS_Store 3 | .AppleDouble 4 | .LSOverride 5 | 6 | # Icon must end with two \r 7 | Icon 8 | 9 | 10 | # Thumbnails 11 | ._* 12 | 13 | # Files that might appear in the root of a volume 14 | .DocumentRevisions-V100 15 | .fseventsd 16 | .Spotlight-V100 17 | .TemporaryItems 18 | .Trashes 19 | .VolumeIcon.icns 20 | .com.apple.timemachine.donotpresent 21 | 22 | # Directories potentially created on remote AFP share 23 | .AppleDB 24 | .AppleDesktop 25 | Network Trash Folder 26 | Temporary Items 27 | .apdisk 28 | 29 | # Bower and NPM libraries 30 | bower_components 31 | node_modules 32 | 33 | # Build files 34 | build 35 | MANIFEST 36 | site 37 | 38 | # PyCharm CE files 39 | .idea/ 40 | 41 | # Byte-compiled / optimized / DLL files 42 | __pycache__/ 43 | *.py[cod] 44 | *$py.class 45 | 46 | # C extensions 47 | *.so 48 | 49 | # Distribution / packaging 50 | .Python 51 | env/ 52 | build/ 53 | develop-eggs/ 54 | dist/ 55 | downloads/ 56 | eggs/ 57 | .eggs/ 58 | lib/ 59 | lib64/ 60 | parts/ 61 | sdist/ 62 | var/ 63 | wheels/ 64 | *.egg-info/ 65 | .installed.cfg 66 | *.egg 67 | 68 | # PyInstaller 69 | # Usually these files are written by a python script from a template 70 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 71 | *.manifest 72 | *.spec 73 | 74 | # Installer logs 75 | pip-log.txt 76 | pip-delete-this-directory.txt 77 | 78 | # Unit test / coverage reports 79 | htmlcov/ 80 | .tox/ 81 | .coverage 82 | .coverage.* 83 | .cache 84 | nosetests.xml 85 | coverage.xml 86 | *,cover 87 | .hypothesis/ 88 | 89 | # Translations 90 | *.mo 91 | *.pot 92 | 93 | # Django stuff: 94 | *.log 95 | local_settings.py 96 | 97 | # Flask stuff: 98 | instance/ 99 | .webassets-cache 100 | 101 | # Scrapy stuff: 102 | .scrapy 103 | 104 | # Sphinx documentation 105 | docs/_build/ 106 | 107 | # PyBuilder 108 | target/ 109 | 110 | # Jupyter Notebook 111 | .ipynb_checkpoints 112 | 113 | # pyenv 114 | .python-version 115 | 116 | # celery beat schedule file 117 | celerybeat-schedule 118 | 119 | # dotenv 120 | .env 121 | 122 | # virtualenv 123 | .venv/ 124 | venv/ 125 | ENV/ 126 | 127 | # Spyder project settings 128 | .spyderproject 129 | 130 | # Rope project settings 131 | .ropeproject 132 | 133 | mkdocs_combine/cli/mkdocs2print.py 134 | -------------------------------------------------------------------------------- /CHANGES: -------------------------------------------------------------------------------- 1 | 0.4.0.0 by Daniel Nüst 2 | 3 | * Add verbose option and some logging 4 | * Single version definition in setup.py 5 | * Switch to mkdocs 1.0.4 or later, incl. support for new "nav" config property, which deprecates "pages", see https://github.com/mkdocs/mkdocs/pull/1504 6 | 7 | 0.3.1.1 by Adam Twardoch: 8 | 9 | * Compatibility fix for unicode filenames 10 | 11 | 0.3.1.0 by Daniel Nüst: 12 | 13 | * Added admonition processing 14 | 15 | 0.3.0.1 by Jeff Hastings: 16 | 17 | * Add ability to insert page breaks between pages 18 | 19 | 0.3.0.0 by Adam Twardoch: 20 | 21 | * Renamed project to 'mkdocs-combine' 22 | * Added more commandline options to mkdocscombine tool 23 | 24 | 0.2.6.3: 25 | 26 | * Added support for pages without titles specified in mkdocs.yml 27 | 28 | 0.2.6: 29 | 30 | * Fixed issues/11 (added support for underwide header rows in tables) 31 | * Fixed issues/9 (added support for list-style pages data structure) 32 | 33 | 0.2.5: 34 | 35 | * Fixed issues/8 (missing empty lines between pages) 36 | * Fixed issues/5 (path delimiter handling on Windows) 37 | * Documented installation on Windows 38 | 39 | 0.2.4: 40 | 41 | * Fixed crash on missing `markdown_extensions` in mkdocs.yml 42 | 43 | 0.2.3: 44 | 45 | * Fixed writing to standard output (broke in 0.2.2). 46 | 47 | 0.2.2: 48 | 49 | * Merged Marcin Klick's Python3 compatibility fixes 50 | * Documented packages required for generating PDF from Pandoc source 51 | 52 | 0.2.1: 53 | 54 | Initial public release. 55 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | Copyright 2015 Johannes Grassler 179 | 180 | Licensed under the Apache License, Version 2.0 (the "License"); 181 | you may not use this file except in compliance with the License. 182 | You may obtain a copy of the License at 183 | 184 | http://www.apache.org/licenses/LICENSE-2.0 185 | 186 | Unless required by applicable law or agreed to in writing, software 187 | distributed under the License is distributed on an "AS IS" BASIS, 188 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 189 | See the License for the specific language governing permissions and 190 | limitations under the License. 191 | 192 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # mkdocs-combine 2 | 3 | **2018-06-05: Note that MkDocs now supports plugins that provide a better architecture for this task. I'll probably replace this project with a fork of [shauser's plugin](https://github.com/shauser/mkdocs-pdf-export-plugin)** — Adam 4 | 5 | [**`mkdocs-combine`**](https://github.com/twardoch/mkdocs-combine/) is a Python module that combines a [MkDocs](http://www.mkdocs.org/)-style Markdown source site into a single Markdown document. This is useful for 6 | 7 | * Generating PDF or EPUB from your MkDocs documentation 8 | * Generating single-page HTML from your MkDocs documentation 9 | * Converting your MkDocs documentation to other formats, such as asciidoc 10 | 11 | The output Markdown document is compatible with [pandoc](http://www.pandoc.org/). 12 | 13 | This package is written in Python 2.7 and relies on `mkdocs` and the Python `Markdown` implementation. Aside from several filters, the module contains a `MkDocsCombiner` class tying them together into a coherent whole, and the command-line tool `mkdocscombine`. 14 | 15 | [`mkdocs-combine`](https://github.com/twardoch/mkdocs-combine/) is maintained by Adam Twardoch. It's a fork of [`mkdocs-pandoc`](https://github.com/jgrassler/mkdocs-pandoc) by Johannes Grassler. 16 | 17 | # Installation 18 | 19 | _Note: The following instructions apply to both Unixoid systems and Windows._ 20 | 21 | If you'd like to use the development version, use 22 | 23 | ``` 24 | pip install git+https://github.com/twardoch/mkdocs-combine.git 25 | ``` 26 | 27 | Note that if you are behind a proxy, you might need to add the `--proxy` option like this 28 | 29 | ``` 30 | pip --proxy=http[s]://user@mydomain:port install ... 31 | ``` 32 | 33 | If you'd like to install a local development version from the current path, use 34 | 35 | ``` 36 | pip install -e . 37 | ``` 38 | 39 | ## Pandoc compatibility 40 | 41 | For generating PDF through `pandoc` you will need to install a few things `pip` won't handle, namely `pandoc` and the somewhat exotic LaTeX packages its default LaTeX template uses. On a Ubuntu 14.04 system this amounts to the following packages: 42 | 43 | ``` 44 | fonts-lmodern 45 | lmodern 46 | pandoc 47 | texlive-base 48 | texlive-latex-extra 49 | texlive-fonts-recommended 50 | texlive-latex-recommended 51 | texlive-xetex 52 | ``` 53 | On a Windows system you can get them through [Chocolatey](https://chocolatey.org/). Once you have Chocolatey up and running the following commands should leave you with everything you need to create PDF output from `pandoc`: 54 | 55 | ``` 56 | choco install python 57 | choco install pandocpdf 58 | ``` 59 | 60 | # Usage 61 | 62 | When executed in the directory where your documentation's `mkdoc.yml` and the `docs/` directory containing the actual documentation resides, `mkdocscombine` should print one long Markdown document suitable for `pandoc` on standard output. The tool also allows to output a long HTML file in addition to, or in place of the Markdown file. 63 | 64 | ``` 65 | usage: mkdocscombine [-h] [-V] [-o OUTFILE] [-f CONFIG_FILE] [-e ENCODING] 66 | [-x EXCLUDE] [-H OUTHTML] [-y | -Y] [-c | -C] [-u | -k] 67 | [-t | -g] [-G WIDTH] [-r | -R] [-a | -A] [-m | -l] 68 | [-i IMAGE_EXT] 69 | 70 | mkdocscombine.py - combines an MkDocs source site into a single Markdown 71 | document 72 | 73 | optional arguments: 74 | -h, --help show this help message and exit 75 | -V, --version show program's version number and exit 76 | -v, --verbose print additional info during execution 77 | 78 | files: 79 | -o OUTFILE, --outfile OUTFILE 80 | write combined Markdown to path ('-' for stdout) 81 | -f CONFIG_FILE, --config-file CONFIG_FILE 82 | MkDocs config file (default: mkdocs.yml) 83 | -e ENCODING, --encoding ENCODING 84 | set encoding for input files (default: utf-8) 85 | -x EXCLUDE, --exclude EXCLUDE 86 | exclude Markdown files from processing (default: none) 87 | -H OUTHTML, --outhtml OUTHTML 88 | write simple HTML to path ('-' for stdout) 89 | 90 | structure: 91 | -y, --meta keep YAML metadata (default) 92 | -Y, --no-meta strip YAML metadata 93 | -c, --titles add titles from mkdocs.yml to Markdown files (default) 94 | -C, --no-titles do not add titles to Markdown files 95 | -u, --up-levels increase ATX header levels in Markdown files (default) 96 | -k, --keep-levels do not increase ATX header levels in Markdown files 97 | -B, --no-page-break do not add page break between pages (default) 98 | -b, --page-break add page break between pages 99 | 100 | tables: 101 | -t, --tables keep original Markdown tables (default) 102 | -g, --grid-tables combine Markdown tables to Pandoc-style grid tables 103 | -G WIDTH, --grid-width WIDTH 104 | char width of converted grid tables (default: 100) 105 | 106 | links: 107 | -r, --refs keep MkDocs-style cross-references 108 | -R, --no-refs replace MkDocs-style cross-references by just their 109 | title (default) 110 | -a, --anchors keep HTML anchor tags 111 | -A, --no-anchors strip out HTML anchor tags (default) 112 | 113 | extras: 114 | -m, --math keep \( \) Markdown math notation as is (default) 115 | -l, --latex combine the \( \) Markdown math into LaTeX $$ inlines 116 | -i IMAGE_EXT, --image-ext IMAGE_EXT 117 | replace image extensions by (default: no replacement) 118 | -d, --admonitions-md convert admonitions to HTML already in the Markdown 119 | ``` 120 | 121 | ## Usage example 122 | 123 | ``` 124 | cd ~/mydocs 125 | mkdocscombine -o mydocs.pd 126 | pandoc --toc -f markdown+grid_tables+table_captions -o mydocs.pdf mydocs.pd # Generate PDF 127 | pandoc --toc -f markdown+grid_tables -t epub -o mydocs.epub mydocs.pd # Generate EPUB 128 | ``` 129 | 130 | # Bugs 131 | 132 | The following things are known to be broken: 133 | 134 | * Line wrapping in table cells will wrap links, which causes whitespace to be inserted in their target URLs, at least in PDF output. While this is a bit of a Pandoc problem, it can and should be fixed in this module. 135 | * [Internal Hyperlinks](http://www.mkdocs.org/user-guide/writing-your-docs/#internal-hyperlinks) between markdown documents will be reduced to their link titles, i.e. they will not be links in the resulting Pandoc document. 136 | 137 | # Copyright 138 | 139 | * © 2015 Johannes Grassler 140 | * © 2017 Adam Twardoch 141 | 142 | Licensed under the Apache License, Version 2.0 (the "License"); 143 | you may not use this file except in compliance with the License. 144 | You may obtain a copy of the License at 145 | 146 | [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0) 147 | 148 | You will also find a copy of the License in the file `LICENSE` in the top level 149 | directory of this source code repository. In case the above URL is unreachable and/or differs from the copy in this file, the file takes precedence. 150 | 151 | Unless required by applicable law or agreed to in writing, software 152 | distributed under the License is distributed on an "AS IS" BASIS, 153 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 154 | 155 | 156 | ### Projects related to Markdown and MkDocs by Adam Twardoch: 157 | 158 | * [https://twardoch.github.io/markdown-rundown/](https://twardoch.github.io/markdown-rundown/) — summary of Markdown formatting styles [git](https://github.com/twardoch/markdown-rundown) 159 | * [https://twardoch.github.io/markdown-steroids/](https://twardoch.github.io/markdown-steroids/) — Some extensions for Python Markdown [git](https://github.com/twardoch/markdown-steroids) 160 | * [https://twardoch.github.io/markdown-utils/](https://twardoch.github.io/markdown-utils/) — various utilities for working with Markdown-based documents [git](https://github.com/twardoch/markdown-utils) 161 | * [https://twardoch.github.io/mkdocs-combine/](https://twardoch.github.io/mkdocs-combine/) — convert an MkDocs Markdown source site to a single Markdown document [git](https://github.com/twardoch/mkdocs-combine) 162 | * [https://github.com/twardoch/noto-mkdocs-theme/tree/rework](https://github.com/twardoch/noto-mkdocs-theme/tree/rework) — great Material Design-inspired theme for MkDocs [git](https://github.com/twardoch/noto-mkdocs-theme) 163 | * [https://twardoch.github.io/clinker-mktheme/](https://twardoch.github.io/clinker-mktheme/) — great theme for MkDocs [git](https://github.com/twardoch/clinker-mktheme) 164 | 165 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-minimal -------------------------------------------------------------------------------- /install-macos.command: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | dir=${0%/*} 4 | if [ "$dir" = "$0" ]; then 5 | dir="." 6 | fi 7 | cd "$dir" 8 | 9 | # Install me 10 | pip install --user --upgrade -r py-requirements.txt 11 | pip install --user --upgrade . 12 | echo "# Done!" 13 | -------------------------------------------------------------------------------- /mkdocs_combine/__init__.py: -------------------------------------------------------------------------------- 1 | from mkdocs_combine.mkdocs_combiner import MkDocsCombiner 2 | -------------------------------------------------------------------------------- /mkdocs_combine/cli/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/twardoch/mkdocs-combine/df0dcdc1f21b290845bf553c4353e9d73a8c09dc/mkdocs_combine/cli/__init__.py -------------------------------------------------------------------------------- /mkdocs_combine/cli/mkdocscombine.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Copyright 2015 Johannes Grassler 4 | # Copyright 2017 Adam Twardoch 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | # mkdocscombine - combines an MkDocs source site into a single Markdown document 19 | 20 | from __future__ import print_function 21 | 22 | import argparse 23 | import codecs 24 | import sys 25 | 26 | import mkdocs_combine 27 | from mkdocs_combine.exceptions import FatalError 28 | 29 | from pkg_resources import get_distribution 30 | __version__ = get_distribution('mkdocs-combine').version 31 | 32 | def stdout_file(encoding): 33 | # Python 2 and Python 3 have mutually incompatible approaches to writing 34 | # encoded data to sys.stdout, so we'll have to pick the appropriate one. 35 | 36 | if sys.version_info.major == 2: 37 | return codecs.getwriter(encoding)(sys.stdout) 38 | elif sys.version_info.major >= 3: 39 | return open(sys.stdout.fileno(), mode='w', encoding=encoding, buffering=1) 40 | 41 | 42 | def parse_args(): 43 | args = argparse.ArgumentParser( 44 | description="mkdocscombine.py " + 45 | "- combines an MkDocs source site into a single Markdown document") 46 | 47 | args.add_argument('-V', '--version', action='version', 48 | version='%(prog)s {version}'.format(version=__version__)) 49 | args.add_argument('-v', '--verbose', dest='verbose', action='store_true', 50 | help="print additional info during execution") 51 | 52 | args_files = args.add_argument_group('files') 53 | args_files.add_argument('-o', '--outfile', dest='outfile', default=None, 54 | help="write combined Markdown to path ('-' for stdout)") 55 | args_files.add_argument('-f', '--config-file', dest='config_file', default='mkdocs.yml', 56 | help="MkDocs config file (default: mkdocs.yml)") 57 | args_files.add_argument('-e', '--encoding', dest='encoding', default='utf-8', 58 | help="set encoding for input files (default: utf-8)") 59 | args_files.add_argument('-x', '--exclude', dest='exclude', default=None, action='append', 60 | help="exclude Markdown files from processing (default: none)") 61 | args_files.add_argument('-H', '--outhtml', dest='outhtml', default=None, 62 | help="write simple HTML to path ('-' for stdout)") 63 | 64 | args_struct = args.add_argument_group('structure') 65 | args_strip_metadata = args_struct.add_mutually_exclusive_group(required=False) 66 | args_strip_metadata.add_argument('-y', '--meta', dest='strip_metadata', action='store_false', 67 | help='keep YAML metadata (default)') 68 | args_strip_metadata.add_argument('-Y', '--no-meta', dest='strip_metadata', action='store_true', 69 | help='strip YAML metadata') 70 | args.set_defaults(strip_metadata=False) 71 | 72 | args_add_chapter_heads = args_struct.add_mutually_exclusive_group(required=False) 73 | args_add_chapter_heads.add_argument('-c', '--titles', dest='add_chapter_heads', action='store_true', 74 | help='add titles from mkdocs.yml to Markdown files (default)') 75 | args_add_chapter_heads.add_argument('-C', '--no-titles', dest='add_chapter_heads', action='store_false', 76 | help='do not add titles to Markdown files') 77 | args.set_defaults(add_chapter_heads=True) 78 | 79 | args_increase_heads = args_struct.add_mutually_exclusive_group(required=False) 80 | args_increase_heads.add_argument('-u', '--up-levels', dest='increase_heads', action='store_true', 81 | help='increase ATX header levels in Markdown files (default)') 82 | args_increase_heads.add_argument('-k', '--keep-levels', dest='increase_heads', action='store_false', 83 | help='do not increase ATX header levels in Markdown files') 84 | args.set_defaults(increase_heads=True) 85 | 86 | args_add_page_break = args_struct.add_mutually_exclusive_group(required=False) 87 | args_add_page_break.add_argument('-B', '--no-page-break', dest='add_page_break', action='store_false', 88 | help='do not add page break between pages (default)') 89 | args_add_page_break.add_argument('-b', '--page-break', dest='add_page_break', action='store_true', 90 | help='add page break between pages') 91 | args.set_defaults(add_page_break=False) 92 | 93 | args_tables = args.add_argument_group('tables') 94 | args_filter_tables = args_tables.add_mutually_exclusive_group(required=False) 95 | args_filter_tables.add_argument('-t', '--tables', dest='filter_tables', action='store_false', 96 | help='keep original Markdown tables (default)') 97 | args_filter_tables.add_argument('-g', '--grid-tables', dest='filter_tables', action='store_true', 98 | help='combine Markdown tables to Pandoc-style grid tables') 99 | args.set_defaults(filter_tables=False) 100 | 101 | args_tables.add_argument('-G', '--grid-width', dest='width', default=100, 102 | help="char width of converted grid tables (default: 100)") 103 | 104 | args_links = args.add_argument_group('links') 105 | args_filter_xrefs = args_links.add_mutually_exclusive_group(required=False) 106 | args_filter_xrefs.add_argument('-r', '--refs', dest='filter_xrefs', action='store_false', 107 | help='keep MkDocs-style cross-references') 108 | args_filter_xrefs.add_argument('-R', '--no-refs', dest='filter_xrefs', action='store_true', 109 | help='replace MkDocs-style cross-references by just their title (default)') 110 | args.set_defaults(filter_xrefs=True) 111 | 112 | args_strip_anchors = args_links.add_mutually_exclusive_group(required=False) 113 | args_strip_anchors.add_argument('-a', '--anchors', dest='strip_anchors', action='store_false', 114 | help='keep HTML anchor tags') 115 | args_strip_anchors.add_argument('-A', '--no-anchors', dest='strip_anchors', action='store_true', 116 | help='strip out HTML anchor tags (default)') 117 | args.set_defaults(strip_anchors=True) 118 | 119 | args_extras = args.add_argument_group('extras') 120 | args_convert_math = args_extras.add_mutually_exclusive_group(required=False) 121 | args_convert_math.add_argument('-m', '--math', dest='convert_math', action='store_false', 122 | help='keep \( \) Markdown math notation as is (default)') 123 | args_convert_math.add_argument('-l', '--latex', dest='convert_math', action='store_true', 124 | help='combine the \( \) Markdown math into LaTeX $$ inlines') 125 | args.set_defaults(convert_math=False) 126 | 127 | args_extras.add_argument('-i', '--image-ext', dest='image_ext', default=None, 128 | help="replace image extensions by (default: no replacement)") 129 | args_extras.add_argument('-d', '--admonitions-md', dest='convert_admonition_md', action='store_true', 130 | help='convert admonitions to HTML already in the Markdown') 131 | 132 | return args.parse_args() 133 | 134 | 135 | def main(): 136 | args = parse_args() 137 | 138 | try: 139 | mkdocs_combiner = mkdocs_combine.MkDocsCombiner( 140 | config_file=args.config_file, 141 | exclude=args.exclude, 142 | image_ext=args.image_ext, 143 | width=args.width, 144 | encoding=args.encoding, 145 | filter_tables=args.filter_tables, 146 | filter_xrefs=args.filter_xrefs, 147 | strip_anchors=args.strip_anchors, 148 | strip_metadata=args.strip_metadata, 149 | convert_math=args.convert_math, 150 | add_chapter_heads=args.add_chapter_heads, 151 | increase_heads=args.increase_heads, 152 | add_page_break=args.add_page_break, 153 | verbose=args.verbose, 154 | convert_admonition_md=args.convert_admonition_md 155 | ) 156 | except FatalError as e: 157 | print(e.message, file=sys.stderr) 158 | return e.status 159 | 160 | mkdocs_combiner.combine() 161 | 162 | combined_md_file = None 163 | if args.outfile == '-': 164 | combined_md_file = stdout_file(args.encoding) 165 | elif args.outfile: 166 | try: 167 | combined_md_file = codecs.open(args.outfile, 'w', encoding=args.encoding) 168 | except IOError as e: 169 | print("Couldn't open %s for writing: %s" % (args.outfile, e.strerror), file=sys.stderr) 170 | if combined_md_file: 171 | combined_md_file.write('\n'.join(mkdocs_combiner.combined_md_lines)) 172 | combined_md_file.close() 173 | 174 | html_file = None 175 | if args.outhtml == '-': 176 | html_file = stdout_file(args.encoding) 177 | elif args.outhtml: 178 | try: 179 | html_file = codecs.open(args.outhtml, 'w', encoding=args.encoding) 180 | except IOError as e: 181 | print("Couldn't open %s for writing: %s" % (args.htmlfile, e.strerror), file=sys.stderr) 182 | if html_file: 183 | html_file.write(mkdocs_combiner.to_html()) 184 | html_file.close() 185 | -------------------------------------------------------------------------------- /mkdocs_combine/exceptions.py: -------------------------------------------------------------------------------- 1 | class FatalError(Exception): 2 | """Exception wrapper that contains an exit status in addition to a message""" 3 | def __init__(self, message, status=1): 4 | self.message = message 5 | self.status = status 6 | -------------------------------------------------------------------------------- /mkdocs_combine/filters/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/twardoch/mkdocs-combine/df0dcdc1f21b290845bf553c4353e9d73a8c09dc/mkdocs_combine/filters/__init__.py -------------------------------------------------------------------------------- /mkdocs_combine/filters/admonitions.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Copyright 2015 Johannes Grassler 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # mdtableconv.py - converts pipe tables to Pandoc's grid tables 18 | 19 | import markdown.extensions.admonition as adm 20 | import markdown.blockparser 21 | from markdown.util import etree 22 | 23 | class AdmonitionFilter(adm.AdmonitionProcessor): 24 | 25 | def __init__(self, encoding='utf-8', tab_length = 4): 26 | self.encoding = encoding 27 | self.tab_length = tab_length 28 | 29 | def blocks(self, lines): 30 | """Groups lines into markdown blocks""" 31 | state = markdown.blockparser.State() 32 | blocks = [] 33 | 34 | # We use three states: start, ``` and '\n' 35 | state.set('start') 36 | 37 | # index of current block 38 | currblock = 0 39 | 40 | for line in lines: 41 | line += '\n' 42 | if state.isstate('start'): 43 | if line[:3] == '```': 44 | state.set('```') 45 | else: 46 | state.set('\n') 47 | blocks.append('') 48 | currblock = len(blocks) - 1 49 | else: 50 | marker = line[:3] # Will capture either '\n' or '```' 51 | if state.isstate(marker): 52 | state.reset() 53 | blocks[currblock] += line 54 | 55 | return blocks 56 | 57 | def run(self, lines): 58 | """Filter method: Passes all blocks through convert_admonition() and returns a list of lines.""" 59 | ret = [] 60 | 61 | blocks = self.blocks(lines) 62 | for block in blocks: 63 | 64 | ret.extend(self.convert_admonition(block)) 65 | 66 | return ret 67 | 68 | def convert_admonition(self, block): 69 | lines = block.split('\n') 70 | 71 | if self.RE.search(block): 72 | 73 | m = self.RE.search(lines.pop(0)) 74 | klass, title = self.get_class_and_title(m) 75 | 76 | lines = list(map(lambda x:self.detab(x)[0], lines)) 77 | lines = '\n'.join(lines[:-1]) 78 | 79 | div = etree.Element('div') 80 | div.set('class', '%s %s' % (self.CLASSNAME, klass)) 81 | if title: 82 | p = etree.SubElement(div, 'p') 83 | p.set('class', self.CLASSNAME_TITLE) 84 | p.text = title 85 | 86 | content = etree.SubElement(div, 'p') 87 | content.text = lines 88 | 89 | string = etree.tostring(div).decode(self.encoding) 90 | lines = [string] 91 | lines.append('') 92 | 93 | return lines 94 | -------------------------------------------------------------------------------- /mkdocs_combine/filters/anchors.py: -------------------------------------------------------------------------------- 1 | # Copyright 2015 Johannes Grassler 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | import re 17 | 18 | class AnchorFilter(object): 19 | """Strips out HTML anchor tags""" 20 | 21 | def run(self, lines): 22 | """Filter method""" 23 | ret = [] 24 | for line in lines: 25 | ret.append(re.sub(r'', '', line)) 26 | 27 | return ret 28 | -------------------------------------------------------------------------------- /mkdocs_combine/filters/chapterhead.py: -------------------------------------------------------------------------------- 1 | # Copyright 2015 Johannes Grassler 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | class ChapterheadFilter(object): 17 | """Filter for adding chapter titles from mkdocs.yml to chapter files""" 18 | 19 | def __init__(self, **kwargs): 20 | self.headlevel = kwargs.get('headlevel', 1) 21 | self.title = kwargs.get('title', None) 22 | if self.title == None: 23 | raise ValueError( 24 | 'Mandatory keyword argument `title` missing.') 25 | 26 | def run(self, lines): 27 | """Filter method""" 28 | 29 | head = [('#' * self.headlevel) + ' ' + self.title, ''] 30 | 31 | head.extend(lines) 32 | 33 | return head 34 | -------------------------------------------------------------------------------- /mkdocs_combine/filters/exclude.py: -------------------------------------------------------------------------------- 1 | # Copyright 2015 Johannes Grassler 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | import re 17 | 18 | class ExcludeFilter(object): 19 | """Removes selected mkdown_include include statements (useful for excluding 20 | a macros include pulled in by every chapter)""" 21 | 22 | def __init__(self, **kwargs): 23 | self.exclude = kwargs.get('exclude', []) 24 | 25 | def run(self, lines): 26 | """Filter method""" 27 | ret = [] 28 | for line in lines: 29 | for exclude in self.exclude: 30 | line = re.sub(r'\{!%s!\}' % exclude, '', line) 31 | ret.append(line) 32 | 33 | return ret 34 | -------------------------------------------------------------------------------- /mkdocs_combine/filters/headlevels.py: -------------------------------------------------------------------------------- 1 | # Copyright 2015 Johannes Grassler 2 | # Copyright 2017 Adam Twardoch 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | import re 17 | 18 | # TODO: Implement handling for Setext style headers. 19 | 20 | class HeadlevelFilter(object): 21 | """Filter for increasing Markdown header levels (only Atx style)""" 22 | 23 | def __init__(self, pages): 24 | max_offset = 0 25 | 26 | # Determine maximum header level from nesting in mkdocs.yml 27 | for page in pages: 28 | if page['level'] > max_offset: 29 | max_offset = page['level'] 30 | 31 | self.offset = max_offset 32 | 33 | 34 | def run(self, lines): 35 | not_in_code_block = True 36 | """Filter method""" 37 | ret = [] 38 | for line in lines: 39 | if '```' in line: 40 | not_in_code_block = not not_in_code_block 41 | if not_in_code_block == True: 42 | line = re.sub(r'^#', '#' * self.offset, line) 43 | line = re.sub(r'^#######+', '######', line) 44 | ret.append(line) 45 | 46 | return ret 47 | -------------------------------------------------------------------------------- /mkdocs_combine/filters/images.py: -------------------------------------------------------------------------------- 1 | # Copyright 2015 Johannes Grassler 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | from __future__ import print_function 17 | import os 18 | import re 19 | 20 | 21 | class ImageFilter(object): 22 | """Filter for adjusting image targets (absolute file names, optionally 23 | different extensions""" 24 | def __init__(self, **kwargs): 25 | self.filename = kwargs.get('filename', None) 26 | self.image_path = kwargs.get('image_path', None) 27 | self.adjust_path = kwargs.get('adjust_path', True) 28 | self.image_ext = kwargs.get('image_ext', None) 29 | 30 | def run(self, lines): 31 | """Filter method""" 32 | # Nothing to do in this case 33 | if (not self.adjust_path) and (not self.image_ext): 34 | return lines 35 | 36 | ret = [] 37 | 38 | for line in lines: 39 | processed = {} 40 | while True: 41 | alt = '' 42 | img_name = '' 43 | 44 | match = re.search(r'!\[(.*?)\]\((.*?)\)', line) 45 | 46 | # Make sure there is in fact an image file name 47 | if match: 48 | # Skip images we already processed 49 | if match.group(0) in processed: 50 | break 51 | # Skip URLs 52 | if re.match('\w+://', match.group(2)): 53 | break 54 | alt = match.group(1) 55 | img_name = match.group(2) 56 | else: 57 | break 58 | 59 | if self.image_ext: 60 | img_name = re.sub(r'\.\w+$', '.' + self.image_ext, img_name) 61 | 62 | if self.adjust_path and (self.image_path or self.filename): 63 | # explicitely specified image path takes precedence over 64 | # path relative to chapter 65 | if self.image_path and self.filename: 66 | img_name = os.path.join( 67 | os.path.abspath(self.image_path), 68 | os.path.dirname(self.filename), 69 | img_name) 70 | 71 | # generate image path relative to file name 72 | if self.filename and (not self.image_path): 73 | img_name = os.path.join( 74 | os.path.abspath( 75 | os.path.dirname(self.filename)), 76 | img_name) 77 | 78 | # handle Windows '\', although this adds a small amount of unnecessary work on Unix systems 79 | img_name = img_name.replace(os.path.sep, '/') 80 | 81 | line = re.sub(r'!\[(.*?)\]\((.*?)\)', 82 | '![%s](%s)' % (alt, img_name), line) 83 | 84 | # Mark this image as processed 85 | processed[match.group(0)] = True 86 | 87 | ret.append(line) 88 | 89 | return ret 90 | -------------------------------------------------------------------------------- /mkdocs_combine/filters/include.py: -------------------------------------------------------------------------------- 1 | # Copyright 2015 Johannes Grassler 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | """Wrapper for using markdown.markdown_include as simple preprocessor (just 16 | pulls in includes without running the HTML generator)""" 17 | 18 | from __future__ import print_function 19 | import markdown_include.include as incl 20 | 21 | 22 | ### This class is merely a wrapper for providing markdown_include.include 23 | class IncludeFilter(incl.IncludePreprocessor): 24 | def __init__(self, **kwargs): 25 | self.base_path = kwargs.get('base_path', '.') 26 | self.encoding = kwargs.get('encoding', 'utf-8') 27 | -------------------------------------------------------------------------------- /mkdocs_combine/filters/math.py: -------------------------------------------------------------------------------- 1 | # Copyright 2015 Johannes Grassler 2 | # Copyright 2016 Kergonath 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | import re 18 | 19 | class MathFilter(object): 20 | """Turn the \( \) Markdown math notation into LaTex $$ inlines""" 21 | 22 | def run(self, lines): 23 | """Filter method""" 24 | ret = [] 25 | for line in lines: 26 | ret.append(re.sub(r'\\\((.*)\\\)', r'$\1$', line)) 27 | 28 | return ret 29 | -------------------------------------------------------------------------------- /mkdocs_combine/filters/metadata.py: -------------------------------------------------------------------------------- 1 | # Copyright 2015 Johannes Grassler 2 | # Copyright 2016 Kergonath 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | import re 18 | 19 | class MetadataFilter(object): 20 | """Turn the \( \) Markdown math notation into LaTex $$ inlines""" 21 | 22 | def run(self, lines): 23 | """Filter method""" 24 | ret = [] 25 | header = True 26 | for line in lines: 27 | if header: 28 | if not re.match(r'^[a-zA-Z\ ]:', line): 29 | header = False 30 | ret.append(line) 31 | else: 32 | ret.append(line) 33 | 34 | return ret 35 | -------------------------------------------------------------------------------- /mkdocs_combine/filters/tables.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Copyright 2015 Johannes Grassler 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # mdtableconv.py - converts pipe tables to Pandoc's grid tables 18 | 19 | import markdown.extensions.tables as tbl 20 | import markdown.blockparser 21 | import re 22 | import string 23 | import textwrap 24 | 25 | class TableFilter(tbl.TableProcessor): 26 | def __init__(self, width=100, encoding='utf-8'): 27 | self.width = width 28 | self.width_default = 20 # Default column width for rogue rows with more cells than the first row. 29 | 30 | 31 | def blocks(self, lines): 32 | """Groups lines into markdown blocks""" 33 | state = markdown.blockparser.State() 34 | blocks = [] 35 | 36 | # We use three states: start, ``` and '\n' 37 | state.set('start') 38 | 39 | # index of current block 40 | currblock = 0 41 | 42 | for line in lines: 43 | line += '\n' 44 | if state.isstate('start'): 45 | if line[:3] == '```': 46 | state.set('```') 47 | else: 48 | state.set('\n') 49 | blocks.append('') 50 | currblock = len(blocks) - 1 51 | else: 52 | marker = line[:3] # Will capture either '\n' or '```' 53 | if state.isstate(marker): 54 | state.reset() 55 | blocks[currblock] += line 56 | 57 | return blocks 58 | 59 | 60 | def convert_table(self, block): 61 | """"Converts a table to grid table format""" 62 | lines_orig = block.split('\n') 63 | lines_orig.pop() # Remove extra newline at end of block 64 | widest_cell = [] # Will hold the width of the widest cell for each column 65 | widest_word = [] # Will hold the width of the widest word for each column 66 | widths = [] # Will hold the computed widths of grid table columns 67 | 68 | rows = [] # Will hold table cells during processing 69 | lines = [] # Will hold the finished table 70 | 71 | has_border = False # Will be set to True if this is a bordered table 72 | 73 | width_unit = 0.0 # This number is used to divide up self.width according 74 | # to the following formula: 75 | # 76 | # self.width = width_unit * maxwidth 77 | # 78 | # Where maxwidth is the sum over all elements of 79 | # widest_cell. 80 | 81 | # Only process tables, leave everything else untouched 82 | 83 | if not self.test(None, block): 84 | return lines_orig 85 | 86 | if lines_orig[0].startswith('|'): 87 | has_border = True 88 | 89 | # Initialize width arrays 90 | 91 | for i in range(0, len(self._split_row(lines_orig[0], has_border))): 92 | widest_cell.append(0) 93 | widest_word.append(0) 94 | widths.append(0) 95 | 96 | # Parse lines into array of cells and record width of widest cell/word 97 | 98 | for line in lines_orig: 99 | row = self._split_row(line, has_border) 100 | # pad widest_cell to account for under length first row 101 | for i in range(0, len(row) - len(widest_cell)): 102 | widest_cell.append(0) 103 | widest_word.append(0) 104 | widths.append(0) 105 | for i in range(0, len(row)): 106 | # Record cell width 107 | if len(row[i]) > widest_cell[i]: 108 | widest_cell[i] = len(row[i]) 109 | # Record longest word 110 | words = row[i].split() 111 | for word in words: 112 | # Keep URLs from throwing the word length count off too badly. 113 | match = re.match(r'\[(.*?)\]\(.*?\)', word) 114 | if match: 115 | word = match.group(1) 116 | 117 | if len(word) > widest_word[i]: 118 | widest_word[i] = len(word) 119 | rows.append(row) 120 | 121 | # Remove table header divider line from rows 122 | rows.pop(1) 123 | 124 | # Compute first approximation of column widths based on maximum cell width 125 | 126 | for width in widest_cell: 127 | width_unit += float(width) 128 | 129 | width_unit = self.width / width_unit 130 | 131 | for i in range(0, len(widest_cell)): 132 | widths[i] = int(widest_cell[i] * width_unit) 133 | 134 | # Add rounding errors to narrowest column 135 | if sum(widths) < self.width: 136 | widths[widths.index(min(widths))] += self.width - sum(widths) 137 | 138 | # Attempt to correct first approximation of column widths based on 139 | # words that fail to fit their cell's width (if this fails textwrap 140 | # will break up long words but since it does not add hyphens this 141 | # should be avoided) 142 | 143 | for i in range(0, len(widths)): 144 | if widths[i] < widest_word[i]: 145 | offset = widest_word[i] - widths[i] 146 | for j in range(0, len(widths)): 147 | if widths[j] - widest_word[j] >= offset: 148 | widths[j] -= offset 149 | widths[i] += offset 150 | offset = 0 151 | 152 | lines.append(self.ruler_line(widths, linetype='-')) 153 | 154 | # Only add header row if it contains more than just whitespace 155 | if ''.join(rows[0]).strip() != '': 156 | lines.extend(self.wrap_row(widths, rows[0])) 157 | lines.append(self.ruler_line(widths, linetype='=')) 158 | 159 | for row in rows[1:]: 160 | # Skip empty rows 161 | if ''.join(row).strip() == '': 162 | continue 163 | lines.extend(self.wrap_row(widths, row)) 164 | lines.append(self.ruler_line(widths, linetype='-')) 165 | 166 | # Append empty line after table 167 | lines.append('') 168 | 169 | return lines 170 | 171 | 172 | def run(self, lines): 173 | """Filter method: Passes all blocks through convert_table() and returns a list of lines.""" 174 | ret = [] 175 | 176 | for block in self.blocks(lines): 177 | ret.extend(self.convert_table(block)) 178 | 179 | return ret 180 | 181 | 182 | def ruler_line(self, widths, linetype='-'): 183 | """Generates a ruler line for separating rows from each other""" 184 | cells = [] 185 | for w in widths: 186 | cells.append(linetype * (w+2)) 187 | return '+' + '+'.join(cells) + '+' 188 | 189 | 190 | def wrap_row(self, widths, row, width_default=None): 191 | """Wraps a single line table row into a fixed width, multi-line table.""" 192 | lines = [] 193 | longest = 0 # longest wrapped column in row 194 | 195 | if not width_default: 196 | width_default = self.width_default 197 | 198 | # Wrap column contents 199 | for i in range(0, len(row)): 200 | w=width_default # column width 201 | 202 | # Only set column width dynamicaly for non-rogue rows 203 | if i < len(widths): 204 | w = widths[i] 205 | 206 | tw = textwrap.TextWrapper(width=w, break_on_hyphens=False) 207 | # Wrap and left-justify 208 | row[i] = tw.wrap(textwrap.dedent(row[i])) 209 | # Pad with spaces up to to fixed column width 210 | for l in range(0, len(row[i])): 211 | row[i][l] += (w - len(row[i][l])) * ' ' 212 | if len(row[i]) > longest: 213 | longest = len(row[i]) 214 | 215 | # Pad all columns to have the same number of lines 216 | for i in range(0, len(row)): 217 | w=width_default # column width 218 | 219 | # Only set column width dynamicaly for non-rogue rows 220 | if i < len(widths): 221 | w = widths[i] 222 | 223 | if len(row[i]) < longest: 224 | for j in range(len(row[i]), longest): 225 | row[i].append(w * ' ') 226 | 227 | for l in range(0,longest): 228 | line = [] 229 | for c in range(len(row)): 230 | line.append(row[c][l]) 231 | line = '| ' + ' | '.join(line) + ' |' 232 | lines.append(line) 233 | 234 | return lines 235 | -------------------------------------------------------------------------------- /mkdocs_combine/filters/toc.py: -------------------------------------------------------------------------------- 1 | # Copyright 2015 Johannes Grassler 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | import re 17 | 18 | class TocFilter(object): 19 | """Strips out python-markdown [TOC] keyword""" 20 | 21 | def run(self, lines): 22 | """Filter method""" 23 | ret = [] 24 | for line in lines: 25 | ret.append(re.sub(r'^\s*\[TOC\]\s*', '', line)) 26 | 27 | return ret 28 | -------------------------------------------------------------------------------- /mkdocs_combine/filters/xref.py: -------------------------------------------------------------------------------- 1 | # Copyright 2015 Johannes Grassler 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | import re 17 | 18 | # TODO: Implement working cross-references (for now they are simply replaced by 19 | # their link titles). 20 | 21 | class XrefFilter(object): 22 | """Replaces mkdocs style cross-references by just their title""" 23 | 24 | def run(self, lines): 25 | """Filter method""" 26 | ret = [] 27 | for line in lines: 28 | while True: 29 | match = re.search(r'[^!]\[([^\]]+?)\]\(([^http].*?)\)', line) 30 | if match != None: 31 | title = match.group(1) 32 | line = re.sub(r'[^!]\[[^\]]+?\]\([^http].*?\)', title, line, count=1) 33 | else: 34 | break 35 | ret.append(line) 36 | 37 | return ret 38 | -------------------------------------------------------------------------------- /mkdocs_combine/mkdocs_combiner.py: -------------------------------------------------------------------------------- 1 | # Copyright 2015 Johannes Grassler 2 | # Copyright 2017 Adam Twardoch 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | import codecs 17 | import os 18 | import sys 19 | 20 | import markdown 21 | import mkdocs.config 22 | import mkdocs.utils 23 | 24 | import mkdocs_combine.filters.anchors 25 | import mkdocs_combine.filters.chapterhead 26 | import mkdocs_combine.filters.exclude 27 | import mkdocs_combine.filters.headlevels 28 | import mkdocs_combine.filters.images 29 | import mkdocs_combine.filters.include 30 | import mkdocs_combine.filters.math 31 | import mkdocs_combine.filters.metadata 32 | import mkdocs_combine.filters.tables 33 | import mkdocs_combine.filters.toc 34 | import mkdocs_combine.filters.xref 35 | import mkdocs_combine.filters.admonitions 36 | from mkdocs_combine.exceptions import FatalError 37 | 38 | 39 | class MkDocsCombiner: 40 | """Top level converter class. Instantiate separately for each mkdocs.yml.""" 41 | 42 | def __init__(self, **kwargs): 43 | self.config_file = kwargs.get('config_file', 'mkdocs.yml') 44 | self.encoding = kwargs.get('encoding', 'utf-8') 45 | self.exclude = kwargs.get('exclude', None) 46 | self.filter_tables = kwargs.get('filter_tables', True) 47 | self.filter_xrefs = kwargs.get('filter_xrefs', True) 48 | self.image_ext = kwargs.get('image_ext', None) 49 | self.strip_anchors = kwargs.get('strip_anchors', True) 50 | self.strip_metadata = kwargs.get('strip_metadata', True) 51 | self.convert_math = kwargs.get('convert_math', True) 52 | self.width = kwargs.get('width', 100) 53 | self.add_chapter_heads = kwargs.get('add_chapter_heads', True) 54 | self.add_page_break = kwargs.get('add_page_break', False) 55 | self.increase_heads = kwargs.get('increase_heads', True) 56 | self.convert_admonition_md = kwargs.get('convert_admonition_md', False) 57 | self.verbose = kwargs.get('verbose', False) 58 | self.combined_md_lines = [] 59 | self.html_bare = u'' 60 | self.html = u'' 61 | 62 | self.log('Arguments: ' + str(kwargs)) 63 | 64 | try: 65 | cfg = codecs.open(self.config_file, 'r', self.encoding) 66 | except IOError as e: 67 | raise FatalError("Couldn't open %s for reading: %s" % (self.config_file, 68 | e.strerror), 1) 69 | 70 | self.config = mkdocs.config.load_config(config_file=self.config_file) 71 | 72 | if not u'docs_dir' in self.config: 73 | self.config[u'docs_dir'] = u'docs' 74 | 75 | if not u'site_dir' in self.config: 76 | self.config[u'site_dir'] = u'site' 77 | 78 | # Set filters depending on markdown extensions from config 79 | # Defaults first... 80 | self.filter_include = False 81 | self.filter_toc = False 82 | 83 | # ...then override defaults based on config, if any: 84 | 85 | if u'markdown_extensions' in self.config: 86 | for ext in self.config[u'markdown_extensions']: 87 | extname = u'' 88 | # extension entries may be dicts (for passing extension parameters) 89 | if type(ext) is dict: 90 | extname = list(ext.keys())[0].split(u'(')[0] 91 | if type(ext) is str or type(ext) is self.encoding: 92 | extname = ext 93 | 94 | if extname == u'markdown_include.include': 95 | self.filter_include = True 96 | if extname == u'toc': 97 | self.filter_toc = True 98 | 99 | cfg.close() 100 | 101 | def log(self, message): 102 | """Print messages if verbose mode is activated""" 103 | if(self.verbose): 104 | print('[mkdocscombine] ' + message) 105 | 106 | def flatten_pages(self, pages, level=1): 107 | """Recursively flattens pages data structure into a one-dimensional data structure""" 108 | flattened = [] 109 | 110 | if sys.version_info.major < 3: 111 | str_type = (str, self.encoding, unicode) 112 | else: 113 | str_type = (str, self.encoding) 114 | 115 | for page in pages: 116 | if type(page) in str_type: 117 | flattened.append( 118 | { 119 | u'file' : page, 120 | u'title': u'%s {: .page-title}' % mkdocs.utils.filename_to_title(page), 121 | u'level': level, 122 | }) 123 | if type(page) is list: 124 | flattened.append( 125 | { 126 | u'file' : page[0], 127 | u'title': u'%s {: .page-title}' % page[1], 128 | u'level': level, 129 | }) 130 | if type(page) is dict: 131 | if type(list(page.values())[0]) in (str, self.encoding): 132 | flattened.append( 133 | { 134 | u'file' : list(page.values())[0], 135 | u'title': u'%s {: .page-title}' % list(page.keys())[0], 136 | u'level': level, 137 | }) 138 | if type(list(page.values())[0]) is list: 139 | # Add the parent section 140 | flattened.append( 141 | { 142 | u'file' : None, 143 | u'title': u'%s {: .page-title}' % list(page.keys())[0], 144 | u'level': level, 145 | }) 146 | # Add children sections 147 | flattened.extend( 148 | self.flatten_pages( 149 | list(page.values())[0], 150 | level + 1) 151 | ) 152 | return flattened 153 | 154 | def combine(self): 155 | """User-facing conversion method. Returns combined document as a list of lines.""" 156 | lines = [] 157 | 158 | if(self.verbose): 159 | self.log('Running mkdocs-combine in verbose mode') 160 | 161 | self.log(u'Configuration: {0}'.format(self.config)) 162 | 163 | pages = [] 164 | if u'pages' in self.config and self.config[u'pages'] is not None: 165 | pages = self.flatten_pages(self.config[u'pages']) 166 | self.log('Pages: ') 167 | else: 168 | if u'nav' in self.config and self.config[u'nav'] is not None: 169 | pages = self.flatten_pages(self.config[u'nav']) 170 | self.log('Pages (using "nav" property): ') 171 | 172 | f_exclude = mkdocs_combine.filters.exclude.ExcludeFilter( 173 | exclude=self.exclude) 174 | 175 | f_include = mkdocs_combine.filters.include.IncludeFilter( 176 | base_path=self.config[u'docs_dir'], 177 | encoding=self.encoding) 178 | 179 | # First, do the processing that must be done on a per-file basis: 180 | # Adjust header levels, insert chapter headings and adjust image paths. 181 | 182 | f_headlevel = mkdocs_combine.filters.headlevels.HeadlevelFilter(pages) 183 | 184 | for page in pages: 185 | lines_tmp = [] 186 | if page[u'file']: 187 | fname = os.path.join(self.config[u'docs_dir'], page[u'file']) 188 | try: 189 | with codecs.open(fname, 'r', self.encoding) as p: 190 | for line in p.readlines(): 191 | lines_tmp.append(line.rstrip()) 192 | except IOError as e: 193 | raise FatalError("Couldn't open %s for reading: %s" % (fname, 194 | e.strerror), 1) 195 | 196 | f_chapterhead = mkdocs_combine.filters.chapterhead.ChapterheadFilter( 197 | headlevel=page[u'level'], 198 | title=page[u'title'] 199 | ) 200 | 201 | f_image = mkdocs_combine.filters.images.ImageFilter( 202 | filename=page[u'file'], 203 | image_path=self.config[u'site_dir'], 204 | image_ext=self.image_ext) 205 | 206 | if self.exclude: 207 | lines_tmp = f_exclude.run(lines_tmp) 208 | 209 | if self.filter_include: 210 | lines_tmp = f_include.run(lines_tmp) 211 | 212 | lines_tmp = mkdocs_combine.filters.metadata.MetadataFilter().run(lines_tmp) 213 | if self.increase_heads: 214 | lines_tmp = f_headlevel.run(lines_tmp) 215 | if self.add_chapter_heads: 216 | lines_tmp = f_chapterhead.run(lines_tmp) 217 | lines_tmp = f_image.run(lines_tmp) 218 | lines.extend(lines_tmp) 219 | # Add an empty line between pages to prevent text from a previous 220 | # file from butting up against headers in a subsequent file. 221 | lines.append('') 222 | if self.add_page_break: 223 | lines.append('\\newpage') 224 | lines.append('') 225 | 226 | # Strip anchor tags 227 | if self.strip_anchors: 228 | self.log('Stripping anchor tags') 229 | lines = mkdocs_combine.filters.anchors.AnchorFilter().run(lines) 230 | 231 | # Convert math expressions 232 | if self.convert_math: 233 | self.log('Converting math expressions') 234 | lines = mkdocs_combine.filters.math.MathFilter().run(lines) 235 | 236 | # Fix cross references 237 | if self.filter_xrefs: 238 | self.log('Fixing cross references') 239 | lines = mkdocs_combine.filters.xref.XrefFilter().run(lines) 240 | 241 | # Convert admonitions already for Markdown output 242 | if self.convert_admonition_md: 243 | self.log('Converting admonitions to HTML in Markdown output') 244 | lines = mkdocs_combine.filters.admonitions.AdmonitionFilter().run(lines) 245 | 246 | if self.filter_toc: 247 | self.log('Creating TOC') 248 | lines = mkdocs_combine.filters.toc.TocFilter().run(lines) 249 | 250 | if self.filter_tables: 251 | self.log('Filtering tables') 252 | lines = mkdocs_combine.filters.tables.TableFilter().run(lines) 253 | 254 | self.combined_md_lines = lines 255 | return (self.combined_md_lines) 256 | 257 | def to_html(self): 258 | md = u"\n".join(self.combined_md_lines) 259 | mkdocs_extensions = self.config.get(u'markdown_extensions', []) 260 | extensions = ['markdown.extensions.attr_list'] 261 | extension_configs = self.config.get(u'mdx_configs', []) 262 | for ext in mkdocs_extensions: 263 | if type(ext) is str or type(ext) is self.encoding: 264 | extname = str(ext) 265 | extensions.append(extname) 266 | elif type(ext) is dict: 267 | extname = str(ext.keys()[0]) 268 | extensions.append(extname) 269 | extension_configs[extname] = ext[extname] 270 | self.html_bare = markdown.markdown(md, extensions=extensions, 271 | extension_configs=extension_configs, 272 | output_format='html5') 273 | self.html = u""" 274 | 275 | 276 | 277 | 278 | 279 | {} 280 | 281 | 282 | """.format(self.html_bare) 283 | return (self.html) 284 | -------------------------------------------------------------------------------- /py-requirements.txt: -------------------------------------------------------------------------------- 1 | Markdown>=3.0.1 2 | mkdocs>=1.0.4 3 | markdown-include>=0.5.1 4 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env/python 2 | 3 | from os import path 4 | 5 | from setuptools import find_packages, setup 6 | 7 | long_description = ( 8 | "mkdocs_combine is a library that combines a MkDocs-style Markdown site " 9 | "(multiple files, with the document structure defined in the MkDocs " 10 | "configuration file mkdocs.yml) into a single Markdown document. " 11 | "The resulting document can be processed by pandoc or other Markdown tools." 12 | "The command line frontend tool mkdocscombine is the primary user interface." 13 | "Derived from https://github.com/jgrassler/mkdocs-pandoc/" 14 | ) 15 | 16 | setup( 17 | name='mkdocs-combine', 18 | 19 | # Versions should comply with PEP440. 20 | version='0.4.0.0', 21 | 22 | description='Combines a MkDocs Markdown site into a single Markdown file', 23 | 24 | long_description=long_description, 25 | 26 | # The project's main homepage. 27 | url='https://github.com/twardoch/mkdocs-combine/', 28 | download_url='https://github.com/twardoch/mkdocs-combine/archive/master.zip', 29 | 30 | # Author details 31 | author='Johannes Grassler', 32 | author_email='johannes@btw23.de', 33 | maintainer='Adam Twardoch', 34 | maintainer_email='adam+github@twardoch.com', 35 | 36 | # Choose your license 37 | license='Apache', 38 | 39 | # See https://pypi.python.org/pypi?%3Aaction=list_classifiers 40 | classifiers=[ 41 | 'Environment :: MacOS X', 42 | "Environment :: Console", 43 | 'Operating System :: MacOS :: MacOS X', 44 | # How mature is this project? Common values are 45 | # 3 - Alpha 46 | # 4 - Beta 47 | # 5 - Production/Stable 48 | 'Development Status :: 3 - Alpha', 49 | # Indicate who your project is intended for 50 | 'Intended Audience :: End Users/Desktop', 51 | 'Intended Audience :: Developers', 52 | 'Intended Audience :: Information Technology', 53 | 'Intended Audience :: System Administrators', 54 | 'Topic :: Documentation', 55 | 'Topic :: Text Processing', 56 | 'Topic :: Text Processing :: Filters', 57 | 'Topic :: Text Processing :: Markup', 58 | 'Topic :: Text Processing :: Markup :: HTML', 59 | 'Topic :: Software Development :: Documentation', 60 | 'Topic :: Software Development :: Libraries :: Python Modules', 61 | 'Natural Language :: English', 62 | # Pick your license as you wish (should match "license" above) 63 | 'License :: OSI Approved :: Apache Software License', 64 | # Specify the Python versions you support here. In particular, ensure 65 | # that you indicate whether you support Python 2, Python 3 or both. 66 | 'Programming Language :: Python :: 2.7', 67 | ], 68 | 69 | # What does your project relate to? 70 | keywords='mkdocs markdown pandoc print inline combine flatten', 71 | # You can just specify the packages manually here if your project is 72 | # simple. Or you can use find_packages(). 73 | packages=find_packages(), 74 | 75 | # List run-time dependencies here. These will be installed by pip when 76 | # your project is installed. For an analysis of "install_requires" vs pip's 77 | # requirements files see: 78 | # https://packaging.python.org/en/latest/requirements.html 79 | install_requires=['mkdocs>=1.0.4', 80 | 'Markdown>=3.0.1', 81 | 'markdown-include>=0.5.1' 82 | ], 83 | 84 | entry_points={ 85 | 'console_scripts': [ 86 | 'mkdocscombine=mkdocs_combine.cli.mkdocscombine:main', 87 | ], 88 | }, 89 | ) 90 | --------------------------------------------------------------------------------