mdbake
A minimal Markdown → HTML documentation site generator.
- Reads all
*.mdfiles recursively from a docs directory - Renders GitHub-flavored Markdown: tables, task lists, strikethrough, autolinks, footnotes, definition lists, Pygments code highlighting
- Builds navigation from
mdbake.yml, or automatically from the directory tree - Rewrites links between
.mdfiles into relative.htmllinks and warns about broken links and missing#anchors - Generates an in-page table of contents from headings
- Full-text search: a section-level index built at build time, searched in the browser in a Web Worker
- Extensible through a middleware chain (frontmatter processing, text substitution, HTML post-processing, ...)
All output links are relative, so the generated site works when opened straight from disk (file://).
Installation
Requires Python 3.10+.
pip install -e . # or: uv pip install -e .
pip install -e '.[dev]' # with pytest
Usage
mdbake build # uses ./mdbake.yml if present, else docs/ -> site/
mdbake build -f path/to/mdbake.yml # explicit config file
mdbake build -d docs -o site # override docs_dir / site_dir
mdbake build --clean --strict # wipe site_dir first; fail on warnings
| Option | Meaning |
|---|---|
-f, --config |
Config file (default: ./mdbake.yml if it exists) |
-d, --docs-dir |
Markdown source directory (overrides config) |
-o, --site-dir |
Output directory (overrides config) |
--clean |
Delete site_dir before building (refuses if it contains docs_dir) |
-s, --strict |
Exit with an error if there were any warnings |
-v, --verbose / -q, --quiet |
More / less output |
Configuration
mdbake.yml (paths are relative to the config file):
site_name: My Docs
docs_dir: docs
site_dir: site
templates_dir: null # optional theme override
toc_depth: 3 # deepest heading level in "On this page"
search: true # build the search index and show the search box
nav: # optional; auto-generated from the dir tree if omitted
- Home: index.md
- Guide:
- guide/install.md # title taken from the page
- Usage: guide/usage.md # explicit title
- GitHub: https://github.com/example/project
middleware:
- mdbake.builtin.draft
- path: mdbake.builtin.frontmatter_defaults:FrontmatterDefaults
options: {defaults: {author: Docs Team}, required: [title]}
extra: # free-form, available in templates
lang: en
Pages and URLs
| Source | Output |
|---|---|
foo/bar.md |
foo/bar.html |
foo/index.md or foo/README.md |
foo/index.html |
| other files (images, ...) | copied as-is |
Dotfiles and dot-directories are ignored. Optional YAML frontmatter at the top of a page is available as page.meta.
Page title: explicit nav title → frontmatter title → first # H1 → file name.
Navigation
Without nav, the directory tree is used: the root index.md first, then pages, then
sub-directories as sections (a directory's index.md becomes the section link). Add
nav_order: <number> to a page's frontmatter to reorder. Pages missing from an explicit
nav are still built, with a warning.
Search
With search: true (the default), every page is split into sections at its headings and
written to _mdbake/search_index.js. In the browser, the index is loaded the first time the
search box is used, and searching runs in a Web Worker, so large pages never block typing.
Results link straight to the matching heading. Press / or Ctrl/Cmd+K to focus the box.
The search works on sites opened from disk (file://) too: the index is loaded with a
<script> tag rather than fetch(), and the worker is created from a Blob URL. If a browser
refuses to start the worker, the search runs on the page instead.
Add search: false to a page's frontmatter to keep it out of the index.
Middleware
A middleware is any module or class exposing some of these hooks. A hook returns the new
value, or None to keep the current one. Middleware runs in config order.
| Hook | Typical use |
|---|---|
on_config(config) |
tweak settings (return config.replace(...)) |
on_files(files, *, config) |
add/remove files |
on_page_source(page, *, site) |
frontmatter processing; set page.skip = True to drop a page |
on_page_markdown(markdown, *, page, site) |
macros, text substitution |
on_page_html(html, *, page, site) |
post-process HTML |
on_nav(nav, *, site) |
reorder or hide navigation |
on_page_context(ctx, *, page, site) |
extra template variables |
on_post_build(*, site) |
sitemap, search index, ... |
md_setup(md) |
register markdown-it plugins |
Specs are dotted paths with an optional :Attr. Classes are instantiated with options
as keyword arguments; modules are used as-is. The config file's directory is on
sys.path, so a local myhooks.py next to mdbake.yml can be loaded directly:
# myhooks.py
from datetime import date
class Stamp:
def __init__(self, format="%Y-%m-%d"):
self.format = format
def on_page_html(self, html, *, page, site):
return html + f"<p><small>Built {date.today():{self.format}}</small></p>"
middleware:
- path: myhooks:Stamp
options: {format: "%d.%m.%Y"}
Built-ins:
mdbake.builtin.draft: drops pages withdraft: true(mdbake.builtin.draft:Draftwithinclude_drafts: truekeeps them)mdbake.builtin.frontmatter_defaults:FrontmatterDefaults: optionsdefaults,required,strict
Theming
The built-in theme (in src/mdbake/theme/) has a left sidebar nav, an "On this page" TOC,
prev/next links, light/dark mode via prefers-color-scheme, and a mobile layout. To customize
it, set templates_dir and put any of base.html, nav.html, toc.html, style.css or
search.js there; missing files fall back to the built-in ones.
Template context: page, nav, toc, config, site_name, extra, base_url,
assets_url, home_url, and url(target) to make a site-root URL relative to the current page.
Development
pytest
mdbake build -d tests/fixtures/docs -o /tmp/fixture-site
Project layout:
src/mdbake/
cli.py command line interface
config.py mdbake.yml loading
files.py file discovery, source → output paths
frontmatter.py YAML frontmatter splitting
markdown.py markdown-it setup, heading ids, highlighting
links.py relative link rewriting
toc.py table of contents
search.py search index (sections per heading)
nav.py navigation (explicit / auto), prev/next
page.py Page model
middleware.py middleware loader and pipeline
builder.py build orchestration
builtin/ bundled middleware
theme/ default templates, CSS and search.js
See BUILDME.md for the original design plan.
Metadata
Release files for mdbake 0.2.0
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 |
|---|---|---|---|---|
| mdbake-0.2.0.tar.gz | 59.1 kB | With provenance | Details for mdbake-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mdbake-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for mdbake-0.2.0-py3-none-any.whl |
Total release size: 92.5 kB
Release files / mdbake-0.2.0.tar.gz
| Download URL | mdbake-0.2.0.tar.gz |
|---|---|
| Size | 59.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3aae8d163c3ddd74a2d0c46af321a454965320f3e1fdd9d2dd134a8d1ffd6b4f
|
|
BLAKE2b-256 checksum How to use checksums |
150ca45e46acf0ccd717909dd215febcafbe49520d998fc722a0b4db8030b43f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.
Transparency logRelease files / mdbake-0.2.0-py3-none-any.whl
| Download URL | mdbake-0.2.0-py3-none-any.whl |
|---|---|
| Size | 33.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
337e8c84b9ae7f7be1564826c700c3b8eadbfd78d6909d248e99f23c5b0411fd
|
|
BLAKE2b-256 checksum How to use checksums |
15a501c66257db80fd4da4f1d4504550cfbdfd2c631b1e0253148f73dc0d0ebe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.
Transparency logSecurity for mdbake 0.2.0
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for mdbake-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.
Transparency logA 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.