md2site
Turn a folder of Markdown into a static, offline-capable HTML docs site — with build-time link checking for humans and AI coding agents.
How it works
md2site at a glance — sketch by Jayfraggs.
Read the sketch left to right:
docs/→ "raw docs": your Markdown stays the source of truth. The folder and the stack of.mdpages on the left are ordinary files with headings, lists and fenced code — the things you commit and the things AI agents write. Any folder depth, any filenames; nothing is converted into a proprietary format.- "transform": a small build machine. The pipe feeds Markdown into the gears. The terminal prompt (
$_) is the CLI —md2site build— and the gears are the pipeline stages: scan → parse → resolve links → render. The hand crank ismd2site watch, which re-runs the machine whenever a file changes. - "live HTML": a themed reading experience, right in the browser. The window on the right shows what comes out:
- Purple sidebar — the navigation tree, generated from your folder structure with zero routing config (the purple is the default accent colour and is configurable).
- Article column — one standalone HTML page per Markdown file, titled from its first
# H1, with a sticky "On this page" outline. - Dark code panel — syntax highlighting done at build time, so no highlighting JavaScript ships to readers.
- Mermaid panel —
```mermaidblocks become diagrams, loaded only on pages that use them. - Search bar and magnifier — instant offline full-text search (Ctrl/Cmd+K).
- Everything opens straight from disk (
file://), fromlocalhostduringwatch, or from any static host.
- The blueprint dimension lines (the arrows labelled
mandl) are purely decorative — a nod to an engineering drawing. They don't correspond to any setting.
Why md2site
- Authoring vs. reading friction: AI agents and developers write Markdown fast, while dense multi-file Markdown is tiring to read raw.
- No heavy generator toolchain: No Node runtime, no framework boilerplate, no rigid directory layout — zero-config builds work out of the box.
- Dead local references solved: Relative
.mdcross-links, Obsidian[[wikilinks]],#anchors, doc assets, and links to repo source files outsidedocs/all resolve cleanly forfile://, editor URIs, or remote repository URLs. - Agent-friendly reference checker:
md2site check --jsonreturns structured diagnostics (file,line,code,suggestion) so an agent can fix broken references in the same loop that wrote them.
Features
- Navigation: Recursive sorted scan, front matter
order/hidden/draftsupport, numeric-prefix stripping, acronym-aware title humanization, collapsible<details>/<summary>sidebar (works without JS), breadcrumbs, and document-order Previous/Next links. - Links & references: Relative/root-relative
.mdlinks, directoryindex.md/README.mdresolution,[[Wikilinks]]and![[embeds]]with nearest-match tie-breaking, heading#anchorvalidation, case-mismatch detection (MD2S006), repo source-file modes (relative,editor,remote,auto), and opt-in inline-code path autolinking. - Reading experience: Flicker-free light/dark toggle (
localStorage+prefers-color-scheme), configurable CSS tokens, build-time Pygments syntax highlighting with one-click Copy buttons, GitHub alerts (> [!NOTE]–[!CAUTION]), task lists, footnotes, scrollable tables, responsive mobile drawer, and print stylesheet. - Search & diagrams: Offline
assets/search-index.jsloaded lazily onCtrl/Cmd+Kwith Unicode prefix matching and<mark>highlights; vendoredmermaid@12.3.0loaded only on pages containing```mermaidfences and re-rendered on theme switch. - Agent integration: Bundled
SKILL.md(md2site init --with-skill),md2site hookpost-edit stdin validator,md2site check --json, andmd2site watchwith Server-Sent Events live reload.
Install
Note: the PyPI distribution name is md2site-cli (the md2site name on PyPI belongs to an unrelated project), while the CLI command and Python package remain md2site. (md2site-cli will be published to PyPI once trusted publishing is enabled; until then, install directly from Git.)
pipx install git+https://github.com/Jayfraggs/md2site.git
Or run without installing:
uvx --from git+https://github.com/Jayfraggs/md2site md2site build
Quick start
$ md2site init docs
Initialized md2site in /path/to/repo/docs
created /path/to/repo/docs/md2site.config.json
created /path/to/repo/docs/custom.css
ensured /path/to/repo/docs/_site
added docs/_site/ to /path/to/repo/.gitignore
$ md2site build docs
Built 2 pages (8 written, 0 unchanged, 0 removed) in 40 ms [0 errors, 0 warnings]
$ md2site check docs --json
{
"version": 1,
"summary": {
"pages": 2,
"errors": 0,
"warnings": 0,
"duration_ms": 5
},
"diagnostics": []
}
Open docs/_site/index.html directly in your browser (file://), or start live reload while editing:
md2site watch docs --open
Commands
| Command | Arguments & flags | Description |
|---|---|---|
init |
[PATH] [--force] [--with-skill] |
Create md2site.config.json, custom.css, _site/, .gitignore entry, and optional SKILL.md |
build |
[PATH] [--config FILE] [--mode relative|editor|remote|auto] [--out DIR] [--strict] [--json] [--quiet] [--drafts] |
Build the static HTML documentation site |
check |
[PATH] [--config FILE] [--strict] [--json] |
Resolve and validate links without writing files |
watch |
[PATH] [--config FILE] [--host 127.0.0.1] [--port 8000] [--open] |
Serve _site/ locally with SSE live reload and incremental rebuilds |
hook |
(reads JSON on stdin) | Post-edit agent hook; prints diagnostics to stderr and exits 2 on issues |
Run md2site --version or md2site <command> --help for full details.
Configuration
md2site works with zero configuration. Place an optional md2site.config.json inside your docs directory to customize behavior (see docs/configuration.md):
| Key | Default | Purpose |
|---|---|---|
site_title |
"Project Documentation" |
Site title shown in header, browser title, and landing page |
docs_dir |
"." |
Source Markdown root relative to the config file |
output_dir |
"_site" |
Generated HTML output directory |
repo_root |
"auto" |
Ancestor .git root (or config dir) used to resolve source links |
exclude |
[] |
POSIX glob patterns excluded from scanning |
source_link_mode |
"relative" |
One of relative, editor, remote, or auto |
wikilinks |
true |
Enable [[Wikilinks]] and ![[embeds]] |
max_highlight_bytes |
262144 |
Max fence bytes for Pygments highlighting (0 = unlimited) |
nav |
null |
Optional explicit sidebar ordering override (null = auto tree) |
search.enabled |
true |
Emit offline assets/search-index.js and enable Ctrl/Cmd+K modal |
search.max_index_bytes |
0 |
Optional byte budget for assets/search-index.js (0 = unlimited) |
Full default md2site.config.json
{
"site_title": "Project Documentation",
"docs_dir": ".",
"output_dir": "_site",
"repo_root": "auto",
"exclude": [],
"source_link_mode": "relative",
"remote_repo_url": "",
"remote_branch": "main",
"editor_scheme": "vscode",
"autolink_code_paths": false,
"wikilinks": true,
"allow_html": true,
"mermaid": true,
"max_highlight_bytes": 262144,
"nav": null,
"search": { "enabled": true, "body_chars": 6000, "max_index_bytes": 0 },
"theme": {
"default_mode": "system",
"accent_color": "#7c3aed",
"accent_color_dark": "#a78bfa",
"code_theme_light": "default",
"code_theme_dark": "github-dark",
"light": { "bg_primary": "#ffffff", "bg_sidebar": "#f8fafc", "text_primary": "#0f172a" },
"dark": { "bg_primary": "#0b0f19", "bg_sidebar": "#111827", "text_primary": "#f1f5f9" },
"font_sans": "system-ui, -apple-system, sans-serif",
"font_mono": "'JetBrains Mono', 'Fira Code', monospace"
}
}
How links are resolved
| Source syntax | Target | Output |
|---|---|---|
[x](./a.md#h) |
.md in docs |
Relative .html#h; anchor validated |
[x](dir/) |
Directory with index.md / README.md |
dir/index.html |
[[Note]], [[Note#H]], [[Note|Label]], [[folder/Note]] |
Page | Relative HTML link (path → stem → title → alias) |
![[img.png]],  |
Asset in docs | Copied to mirrored path, relative URL |
[x](../src/server.py#L42) |
File outside docs, inside repo_root |
Rewritten per source_link_mode |
 |
Image outside docs | Copied to _site/_external/<repo-relative path> |
http(s)://, mailto:, tel: |
External | Untouched; http(s):// gets class="external" and rel="noopener" |
#anchor |
Same page | Validated against heading IDs |
/abs/path |
Root-relative | Treated as relative to docs_dir |
source_link_mode
relative— exact relative path back to the file on disk (e.g.../../src/server.py#L42).editor— IDE URI (e.g.vscode://file/<abs-path>:42).remote— repository blob URL ({remote_repo_url}/blob/{remote_branch}/src/server.py#L42).auto— emitshrefasrelativeplusdata-remote, swapping to remote on non-local HTTP hosts.
Diagnostics codes
| Code | Meaning |
|---|---|
MD2S001 |
Broken Markdown link (target .md not found) or missing explicit nav target |
MD2S002 |
Broken file/asset link |
MD2S003 |
Ambiguous wikilink (resolved to nearest) |
MD2S004 |
Unresolved wikilink |
MD2S005 |
Broken #anchor heading fragment |
MD2S006 |
Case mismatch (works on case-insensitive FS, breaks on Linux) |
MD2S007 |
Target escapes repo_root |
MD2S008 |
Output path or asset collision |
MD2S009 |
Bad front matter or invalid UTF-8 bytes |
MD2S010 |
remote/auto mode without remote_repo_url |
MD2S011 |
Cross-filesystem relative repo-file fallback when --out cannot reach repo_root |
Works offline, from file://
Browsers enforce strict restrictions when opening HTML files straight from disk:
- No
fetch()of local JSON: search emitsassets/search-index.js(window.__MD2SITE_INDEX__=[...];) and injects it via a classic<script>tag instead of fetching JSON. - No ES modules or
<base>tags: scripts use classic<script defer>and every link/asset uses explicit relative paths (./,../). - No bare directory links: folder links always resolve to explicit
…/index.htmlfiles. - Zero runtime network requests: system font stacks by default, build-time Pygments CSS, and vendored
mermaid.min.js.
For AI agents
- Install the skill with
md2site init docs --with-skill(copies SKILL.md to.claude/skills/md2site/SKILL.md). - Or add a post-edit hook (
md2site hook) andAGENTS.mdsnippet — see docs/agents.md. - Typical agent loop: edit Markdown →
md2site check --json→ fix diagnostics viasuggestion→md2site build.
Performance
- Cold build of 100 pages (~2 KB each with Python code blocks, cross-links, and GFM tables): ~468 ms (0.47 s) on a Linux x86_64 VM (Python 3.12).
- Incremental
watchre-renders only the edited page andsearch-index.jswhen headings, metadata, and outgoing link targets are unchanged; unchanged outputs are skipped by content comparison.
Non-goals
Plugin API, versioned docs, i18n, hosting/deployment tooling, WYSIWYG editing, server-side search, Node build toolchain, MDX, theme marketplace, and built-in PDF export (use browser print).
Development
git clone https://github.com/Jayfraggs/md2site.git
cd md2site
python -m venv .venv
.venv/bin/pip install -e ".[dev]"
.venv/bin/ruff check .
.venv/bin/ruff format --check .
.venv/bin/pytest -q --cov=md2site --cov-report=term-missing
.venv/bin/md2site build docs --strict
See tests/README.md for fixture and golden snapshot instructions, and docs/architecture.md for the pipeline overview.
Contributing
Issues and pull requests are welcome. Please run ruff check ., ruff format --check ., and pytest -q before submitting changes, and follow Conventional Commits.
License
MIT © 2026 Jayfraggs. See THIRD_PARTY_LICENSES.md for vendored Mermaid license details.
Credits
Built on markdown-it-py, mdit-py-plugins, Pygments, Jinja2, watchdog, and Mermaid.
Metadata
Release files for md2site-cli 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 |
|---|---|---|---|---|
| md2site_cli-0.2.0.tar.gz | 2.6 MB | With provenance | Details for md2site_cli-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| md2site_cli-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for md2site_cli-0.2.0-py3-none-any.whl |
Total release size: 4.2 MB
Release files / md2site_cli-0.2.0.tar.gz
| Download URL | md2site_cli-0.2.0.tar.gz |
|---|---|
| Size | 2.6 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a4fc1d15ee0f0f94e4b1efeeb5a06c0a3942b245fd7c6f33dac584503dd2e8c8
|
|
BLAKE2b-256 checksum How to use checksums |
f99a143cfdc5e2a90d64efd6aba7bf3e515aafd89b45030e5581c9c50290d0f0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Dec 5, 2026.
Transparency logRelease files / md2site_cli-0.2.0-py3-none-any.whl
| Download URL | md2site_cli-0.2.0-py3-none-any.whl |
|---|---|
| Size | 1.7 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
394f597943a44b82364aac47eca94bf58b13d6d638d5d7ba812b3482e225ac36
|
|
BLAKE2b-256 checksum How to use checksums |
e7862ebab7d598c3543e668e588f05b7efab10a7d8a39f522a860a3fc8c6af7d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Dec 5, 2026.
Transparency logSecurity for md2site-cli 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 md2site_cli-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 Dec 5, 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.