Skip to main content

mdbake

A minimal Markdown → HTML documentation site generator.

  • Reads all *.md files 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 .md files into relative .html links 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
mdbake watch                          # build, serve on :8000, rebuild + reload browser on changes
mdbake serve                          # serve the already built site_dir on :8000
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

mdbake watch takes -f, -d, -o, -v as above, plus --host (default 127.0.0.1), -p, --port (default 8000) and --open (open a browser). It watches docs_dir, the config file and templates_dir, rebuilds on changes (errors are logged, the server keeps running) and reloads open pages via livereload. mdbake serve takes -f, -o, --host and -p, --port and just serves site_dir over HTTP.

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.

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 with draft: true (mdbake.builtin.draft:Draft with include_drafts: true keeps them)
  • mdbake.builtin.frontmatter_defaults:FrontmatterDefaults: options defaults, 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.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mdbake 0.2.1
File Size Uploaded Provenance Actions
mdbake-0.2.1.tar.gz 65.5 kB With provenance Details for mdbake-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mdbake 0.2.1
File Interpreter ABI Platform Actions
mdbake-0.2.1-py3-none-any.whl Python 3 none any Details for mdbake-0.2.1-py3-none-any.whl

Total release size: 100.1 kB

Release files / mdbake-0.2.1.tar.gz

Download URL mdbake-0.2.1.tar.gz
Size 65.5 kB
Tags Source
SHA-256 checksum
How to use checksums
fc68d4f76aa51d15d8a1f8eed5e8ab368ba3802f6c43cdec59389d256d64db34
BLAKE2b-256 checksum
How to use checksums
b7329c63398a82dcb15b2c593ca34e13c802c625b1de855716b0388551e87d91
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 log

Release files / mdbake-0.2.1-py3-none-any.whl

Download URL mdbake-0.2.1-py3-none-any.whl
Size 34.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d3d07bb3e12f0924ec612ae84e7e7ab1f8cd919b374042690cc788ceea5b1d77
BLAKE2b-256 checksum
How to use checksums
5f0c59c24a2ab1b7015c2464c0a3a24dc132201af87ff8deba64bf9c78455927
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 log

Security for mdbake 0.2.1

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.

Select from 2 files

Attestation for mdbake-0.2.1.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 log

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page