MkDocs Manpage
MkDocs plugin to generate a manpage from the documentation site.
Requirements
Pandoc must be installed and available as pandoc.
Installation
pip install mkdocs-manpage[preprocess]
Usage
# mkdocs.yml
plugins:
- manpage:
pages:
- title: My Project # defaults to site name
output: share/man/man1/my-project.1
inputs:
- index.md
- usage.md
- title: my-project API
header: Python Library APIs # defaults to common header for section 3 (see `man man`)
output: share/man/man3/my_project.3
inputs:
- reference/my_project/*.md
To enable/disable the plugin with an environment variable:
# mkdocs.yml
plugins:
- manpage:
enabled: !ENV [MANPAGE, false]
Then set the environment variable and run MkDocs:
MANPAGE=true mkdocs build
Pre-processing HTML
This plugin works by concatenating the HTML from all selected pages into a single file that is then converted to a manual page using Pandoc.
With a complete conversion, the final manual page will not look so good. For example images and SVG will be rendered as long strings of data and/or URIs. So this plugin allows users to pre-process the HTML, to remove unwanted HTML elements before converting the whole thing to a manpage.
First, you must make sure to install the preprocess extra:
pip install mkdocs-manpage[preprocess]
To pre-process the HTML, we use BeautifulSoup.
Users have to write their own preprocess function in order to modify the soup
returned by BeautifulSoup:
from bs4 import BeautifulSoup, Tag
def to_remove(tag: Tag) -> bool:
# remove images and SVGs
if tag.name in {"img", "svg"}:
return True
# remove links containing images or SVGs
if tag.name == "a" and tag.img and to_remove(tag.img):
return True
# remove permalinks
if tag.name == "a" and "headerlink" in tag.get("class", ()):
return True
return False
def preprocess(soup: BeautifulSoup, output: str) -> None:
for element in soup.find_all(to_remove):
element.decompose()
Then, instruct the plugin to use this module and its preprocess function:
plugins:
- manpage:
preprocess: scripts/preprocess.py
See the documentation of both [BeautifulSoup][bs4.BeautifulSoup] and [Tag][bs4.Tag]
to know what methods are available to correctly select the elements to remove.
The alternative to HTML processing for improving the final manpage is disabling some options from other plugins/extensions:
-
no source code through
mkdocstrings:- mkdocstrings: handlers: python: options: show_source: !ENV [SHOW_SOURCE, true]
-
no permalink through
toc:markdown_extensions: - toc: permalink: !ENV [PERMALINK, true]
Then set these environment variables before building the documentation and generating the manpage:
export MANPAGE=true
export PERMALINK=false
export SHOW_SOURCE=false
mkdocs build
Sponsors
Metadata
Release files for mkdocs-manpage 2.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mkdocs_manpage-2.0.2.tar.gz | 43.7 kB | Without provenance | Details for mkdocs_manpage-2.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mkdocs_manpage-2.0.2-py3-none-any.whl | Python 3 | none | any | Details for mkdocs_manpage-2.0.2-py3-none-any.whl |
Total release size: 70.2 kB
Release files / mkdocs_manpage-2.0.2.tar.gz
| Download URL | mkdocs_manpage-2.0.2.tar.gz |
|---|---|
| Size | 43.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e6a2e308c71b60bbb045dd4a5562866af4d7dad64ef893ebe4cd15621d21fe6b
|
|
BLAKE2b-256 checksum How to use checksums |
2e5a03c401d0a07cd44574d1d68ef61ecf2de2e27707d82a264e347e244872a5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.8
|
Release files / mkdocs_manpage-2.0.2-py3-none-any.whl
| Download URL | mkdocs_manpage-2.0.2-py3-none-any.whl |
|---|---|
| Size | 26.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5775c3ed7df286556fae7861495cbb624145b0f86fe18bddf8a52cd0d6e2e387
|
|
BLAKE2b-256 checksum How to use checksums |
6c308637687f0f329309b3144d4e7ac0c34a3aa35fa9cc29d94c1c0861f313fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.8
|
Security for mkdocs-manpage 2.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.