A MkDocs extension for rendering tree-style code blocks and directory structures.
Project description
mkdocs-treeblocks
Revised on: 06-13-2026 by: Joshua Mullenberg
mkdocs-treeblocks is a MkDocs plugin for rendering readable tree-style blocks in documentation.
The goal is to make directory structures, file trees, project layouts, and related hierarchy examples easier to write, read, and maintain in MkDocs documentation.
[!NOTE] This project is currently in development. Syntax, behavior, and package interfaces are still subject to change.
Initial purpose
This project grew from a need to create clean, text-based tree-style blocks directly in documentation using simple Markdown syntax.
The goal is to avoid switching to a separate app, copying output from a web tool, manually inserting Unicode tree characters, or wrestling with tree command filters just to produce a curated directory structure for documentation.
mkdocs-treeblocks provides a small, predictable syntax that renders tree structures consistently in MkDocs sites.
Syntax
Tree blocks are written as fenced Markdown code blocks. Use three backticks (```) to open and close the block, with tree as the language identifier.
The plugin converts the indentation into a tree structure, and then formats that structure into a fenced text-block using Unicode tree connectors.
Indentation may use either four spaces or one tab per level, but cannot use both indentation styles within the same tree block. Text and spacing after the structural indentation are preserved, allowing filenames, comments, and annotations to remain aligned.
Only one root node is allowed per tree block.
| Syntax by example | Rendered output |
|---|---|
|
|
Installation, testing, and usage
Clone the repository, create and activate a virtual environment, then install the project in editable mode with its development dependencies:
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install -e ".[dev]"
The editable install registers the treeblocks plugin with MkDocs and allows local source changes to take effect without reinstalling the package.
Run the test suite:
python -m pytest
Enable the plugin in mkdocs.yml:
plugins:
- treeblocks
Then write a fenced tree block in a Markdown page:
```tree
docs/
index.md
guides/
install.md
```
During the MkDocs build, the plugin transforms the source into a fenced text block containing the rendered tree.
Current implementation status
Implemented:
- Parse indented text into a tree structure with
parse_tree(). - Render a parsed tree as plain text with
render_tree(). - Use Unicode tree connectors such as
├──,└──, and│. - Preserve original node text, including aligned comments and annotations.
- Transform fenced Markdown
treeblocks into rendered fencedtextblocks withtransform_markdown(). - Leave non-
treefenced code blocks unchanged. - Integrate with MkDocs through the
treeblocksplugin. - Raise MkDocs
PluginErrorfor invalid tree blocks. - Include the source file and tree-block starting line in MkDocs parse errors when page context is available.
- Test parser, renderer, Markdown transformer, MkDocs plugin behavior, and Material for MkDocs compatibility with
pytest. - Material for Mkdocs compatibility testing.
Potential future enhancements:
- Error messages include exact malformed line inside the tree block.
- Custom HTML rendering.
- Dedicated CSS styling.
- Optional automatic directory slash handling.
Project Roadmap
Phase 1: Scaffold and concept
- Create the project
- Set up the GitHub repository
- Document the purpose and syntax
- Add placeholder tests
- Create the initial README
- Make the first commit
Phase 2: Parser MVP
- Choose the first supported syntax
- Parse a small indented tree
- Add parser tests
- Add incremental documentation in /docs/
Phase 3: Renderer MVP
- Define renderer MVP behavior
- Add renderer tests
- Implement a plain Python renderer
- Document renderer behavior
Phase 4: Markdown transform MVP
- Choose fenced
treeblocks as the first supported Markdown source syntax - Detect and transform tree blocks in Markdown
- Replace transformed tree blocks with fenced
textblocks - Keep the transformer independent from MkDocs integration
Phase 5: MkDocs plugin MVP
- Add a minimal MkDocs plugin
- Register the plugin with MkDocs
- Add a minimal MkDocs fixture.
- Add MkDocs integration tests.
- Wrap parser failures as MkDocs
PluginError
Phase 6: Error handling & testing
- Add source file and tree-block starting line diagnostics for parse errors.
- Test with Material for MkDocs.
Phase 7: Publish initial release
- Finalize package metadata in
pyproject.toml. - Install build tooling and create distribution packages.
- Test the built wheel in a clean virtual environment
- Publish the release to PyPI
Phase 8: Documentation Polish
- Update current documentation.
- Verify documentation includes installation, usage, and examples.
- Document limitations and troubleshooting notes.
- Set up GitHub issue and feature-request tracking.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mkdocs_treeblocks-0.1.0.tar.gz.
File metadata
- Download URL: mkdocs_treeblocks-0.1.0.tar.gz
- Upload date:
- Size: 9.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4935527537369abaa601ca9dc07d9feab37b8ef78adacb2bf1c071d39c14d49
|
|
| MD5 |
ef942917739dfc0b852d36f99972dadb
|
|
| BLAKE2b-256 |
506bfc731e8e9f089e57f46334b2e0f7999b92149234f02630c07651d39d6119
|
File details
Details for the file mkdocs_treeblocks-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mkdocs_treeblocks-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3f3f26a58b642559c411ec166163403c303928f1d6729ad07efb9bcef6bb9e29
|
|
| MD5 |
67753554fb03741ae2a7183c9961c498
|
|
| BLAKE2b-256 |
10a0d3cb8803fc6449d50163342e5066f810791b821dd7ae2fc5e5e3910bc25f
|