Skip to content

Commit e89a90e

Browse files
authored
Merge pull request #5 from python-project-templates/tkp/documentation
Expand documentation and Mermaid examples
2 parents 1b79d1b + 59872b7 commit e89a90e

32 files changed

Lines changed: 1031 additions & 55 deletions

‎.gitignore‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,4 @@ AGENTS.md
161161
.github/hooks/sdlc.json
162162
.superpowers
163163

164-
!docs/src/index.md
164+
!docs/index.md

‎Makefile‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ lint-js: ## run js linter
4444
cd js; pnpm lint
4545

4646
lint-docs: ## lint docs with mdformat and codespell
47-
python -m mdformat --check README.md docs/src
48-
python -m codespell_lib README.md docs/src
47+
python -m mdformat --check README.md docs/index.md docs/src
48+
python -m codespell_lib README.md docs/index.md docs/src
4949

5050
lint: lint-js lint-py lint-docs ## run project linters
5151

@@ -61,8 +61,8 @@ fix-js: ## fix js formatting
6161
cd js; pnpm fix
6262

6363
fix-docs: ## autoformat docs with mdformat and codespell
64-
python -m mdformat README.md docs/src
65-
python -m codespell_lib --write README.md docs/src
64+
python -m mdformat README.md docs/index.md docs/src
65+
python -m codespell_lib --write README.md docs/index.md docs/src
6666

6767
fix: fix-js fix-py fix-docs ## run project autoformatters
6868

‎README.md‎

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ Pele mermaid diagrams for Sphinx
99

1010
## Usage
1111

12-
Install and enable the extension:
12+
Install the development version from the repository, then enable the extension.
13+
Building from source requires Git, Node.js 22+, and pnpm 11.11.0 in addition to
14+
Python 3.11+:
1315

1416
```sh
15-
pip install sphinx-pele
17+
python -m pip install "sphinx-pele @ git+https://github.com/python-project-templates/sphinx-pele.git@main"
1618
```
1719

1820
```python
@@ -31,9 +33,21 @@ pele_options = {"zoom": "auto"}
3133
MyST Markdown `mermaid` fences and external `.mmd` files also work. Replace
3234
`sphinxcontrib.mermaid` in `extensions` when migrating.
3335

34-
See [usage](docs/src/usage.md), [configuration](docs/src/configuration.md), and
35-
[examples](docs/src/examples.md). HTML uses bundled Pele assets. Other builders
36-
retain Mermaid source.
36+
## Documentation
3737

38-
-> [!NOTE]
39-
-> This library was generated using [copier](https://copier.readthedocs.io/en/stable/) from the [Base Python Project Template repository](https://github.com/python-project-templates/base).
38+
Start with the [first-diagram tutorial](docs/src/tutorial.md), or follow
39+
[how to add diagrams](docs/src/usage.md) in an existing Sphinx project.
40+
41+
- [Styling and themes](docs/src/styling.md)
42+
- [Migration from sphinxcontrib-mermaid](docs/src/migration.md)
43+
- [Configuration reference](docs/src/configuration.md)
44+
- [Diagram gallery](docs/src/examples.md) and [reStructuredText examples](docs/src/rst-examples.rst)
45+
- [Troubleshooting](docs/src/troubleshooting.md)
46+
- [Rendering and non-HTML output](docs/src/rendering.md)
47+
- [Local development](docs/src/development.md)
48+
49+
Build the documentation with `python -m sphinx -W -b html docs docs/_build/html`.
50+
See the [documentation homepage](docs/index.md) for the full navigation.
51+
52+
> [!NOTE]
53+
> This library was generated using [copier](https://copier.readthedocs.io/en/stable/) from the [Base Python Project Template repository](https://github.com/python-project-templates/base).

‎docs/conf.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
55
extensions = ["myst_parser", "sphinx_pele"]
66
project = "sphinx-pele"
7-
root_doc = "src/index"
8-
exclude_patterns = ["_build"]
7+
root_doc = "index"
8+
exclude_patterns = ["_build", "html"]
99
html_theme = "alabaster"
1010
pele_options = {"zoom": False}

‎docs/index.md‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# sphinx-pele
2+
3+
Render Mermaid diagrams in Sphinx with bundled Pele assets. HTML readers get
4+
responsive SVG and optional zoom controls; other builders retain Mermaid source.
5+
6+
## Start with a working diagram
7+
8+
The tutorial takes you from an empty directory to a page with a captioned,
9+
zoomable diagram.
10+
11+
```{toctree}
12+
:maxdepth: 1
13+
:caption: Tutorial
14+
15+
src/tutorial
16+
```
17+
18+
## Solve an authoring task
19+
20+
These guides cover existing Sphinx projects, visual customization, migration,
21+
and local checks.
22+
23+
```{toctree}
24+
:maxdepth: 1
25+
:caption: How-to guides
26+
27+
src/usage
28+
src/styling
29+
src/migration
30+
src/troubleshooting
31+
src/development
32+
```
33+
34+
## Look up options and examples
35+
36+
The reference records supported settings and their precedence. The example
37+
pages pair reusable source with output from the bundled renderer.
38+
39+
```{toctree}
40+
:maxdepth: 1
41+
:caption: Reference
42+
43+
src/configuration
44+
src/examples
45+
src/rst-examples
46+
```
47+
48+
## Understand the rendering model
49+
50+
Learn why diagrams render in the browser and what that means for layout,
51+
configuration, and non-HTML output.
52+
53+
```{toctree}
54+
:maxdepth: 1
55+
:caption: Explanation
56+
57+
src/rendering
58+
```

‎docs/src/configuration.md‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Configuration reference
22

3+
## Requirements
4+
5+
| Component | Requirement |
6+
| ---------------- | ----------------------------------------------------------------- |
7+
| Python | 3.11 or newer |
8+
| Sphinx | 7.4 or newer |
9+
| MyST | Optional, for Markdown documents |
10+
| Node.js and pnpm | Needed to build from source; not needed to use an installed wheel |
11+
312
## Sphinx settings
413

514
| Setting | Default | Meaning |
@@ -11,6 +20,8 @@ Pele 1.6.0 is bundled in the wheel. HTML documentation uses local JavaScript and
1120
CSS, with no CDN or Node.js runtime requirement. Building the package from source
1221
requires Node.js and pnpm.
1322

23+
(diagram-configuration)=
24+
1425
## Diagram configuration
1526

1627
The `pele` mapping in **diagram** YAML frontmatter accepts the same options as
@@ -46,6 +57,10 @@ The extension accepts these JSON-compatible [Pele options](https://pele.run/api)
4657
| `zoom` | Boolean, `auto`, or zoom options mapping |
4758

4859
Zoom mappings accept Pele's `always`, `maxScale`, `controls`, and `labels` options.
60+
`labels` is a mapping with `zoomIn`, `zoomOut`, and `reset` strings. The default
61+
`zoom: "auto"` shows controls when a diagram shrinks to fit; `true` always enables
62+
zoom and `false` disables it. The documentation gallery explicitly disables zoom
63+
by default and enables it on selected examples.
4964
Pele supplies defaults for omitted values. Mounting measures the container width;
5065
`:width:` controls the container's available width. `maxWidth` is accepted for API
5166
compatibility but Pele's mount operation uses the measured width.
@@ -95,3 +110,21 @@ Pele zoom controls. Without JavaScript, escaped Mermaid source remains visible.
95110
Text, LaTeX, man, and other non-HTML builders emit source as a literal block;
96111
PDF/image export is not implemented. Mermaid CLI options, D3 zoom, and
97112
`sphinxcontrib.mermaid`'s class-tree generator are not supported.
113+
114+
## Errors
115+
116+
| Condition | Result |
117+
| ----------------------------------------------------------- | ------------------------------------------------------ |
118+
| Invalid `pele_options` or `pele_css_variables` in `conf.py` | Sphinx configuration error. |
119+
| Both Mermaid extensions enabled | Sphinx configuration error. |
120+
| Empty directive, missing file, or invalid directive option | Document parsing error. |
121+
| Invalid diagram frontmatter or `pele` option | `pele.config` warning; source remains a literal block. |
122+
| Missing packaged browser assets | HTML builder initialization error. |
123+
| Invalid Mermaid syntax or a rendering limit exceeded | Browser error display from Pele. |
124+
125+
The extension validates the top-level types of renderer options. Nested Mermaid
126+
settings and zoom mapping contents are passed to Pele; they do not receive a
127+
complete schema check in Python. Date-like YAML values must be quoted when used
128+
as strings; `now` accepts a numeric timestamp, not a YAML date.
129+
130+
See [troubleshooting](troubleshooting.md) for recovery steps.

‎docs/src/development.md‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# How to build and check the documentation locally
2+
3+
Start from a repository checkout with Python 3.11+, Node.js 22+, pnpm, and `uv`
4+
installed. Use pnpm 11.11.0 to match the CI setup used for this project.
5+
6+
```sh
7+
uv venv
8+
. .venv/bin/activate
9+
make develop
10+
python -m sphinx -W -b html docs docs/_build/html
11+
python -m http.server 8000 --directory docs/_build/html
12+
```
13+
14+
Open `http://localhost:8000/`. On Windows, activate the environment with
15+
`.venv\Scripts\activate`.
16+
17+
## Add a gallery example
18+
19+
Create a UTF-8 `.mmd` file in `docs/src/examples/`. In `docs/src/examples.md`, add a
20+
source listing and a rendering directive that both read it:
21+
22+
````markdown
23+
## Review flow
24+
25+
```{literalinclude} examples/review.mmd
26+
:language: text
27+
```
28+
29+
```{mermaid} examples/review.mmd
30+
```
31+
````
32+
33+
Use `text` for the source listing so it remains visible as code. A source listing
34+
with language `mermaid` would itself render as a second diagram.
35+
36+
Update the gallery's expected diagram count in `js/tests/index.spec.js`. The
37+
browser checks should fail if a new example produces an error instead of SVG.
38+
39+
## Run the checks
40+
41+
```sh
42+
make lint
43+
make check-types
44+
make test
45+
python -m sphinx -W -b text docs docs/_build/text
46+
```
47+
48+
`make test` runs Python integration tests and Chromium tests against built docs.
49+
Keep port 3000 available for the browser test server. For a docs-only edit,
50+
`make lint-docs` and `make test-js` provide the focused checks.
51+
52+
Rebuild the bundle with `pnpm --dir js build` after editing browser code or
53+
updating Pele. Before changing packaging, also run `make build` and
54+
`make check-dist`.

0 commit comments

Comments
 (0)