Skip to content

Commit acdd892

Browse files
authored
Add instructions to contributing guide about executable docs (#3645)
1 parent 87d2041 commit acdd892

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

docs/contributing.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,40 @@ Hatch can also be used to serve continuously updating version of the documentati
173173
hatch --env docs run serve
174174
```
175175

176+
#### Adding executable code blocks in the documentation
177+
178+
Zarr uses [Markdown Exec](https://pawamoy.github.io/markdown-exec/usage/) to execute code blocks in Markdown files. Add `exec="on"` to a code block header for it to be executed when the docs are built. For example:
179+
180+
````md
181+
```python exec="on"
182+
print("Hello world")
183+
```
184+
````
185+
186+
Below are other useful options that can be added to the code block. See [Markdown Exec's documentation](https://pawamoy.github.io/markdown-exec/usage/#options-summary) for a full list:
187+
188+
- `source="above"` makes sure the code within the code block is also rendered in the documentation (rather than just the output).
189+
- `session="<name-of-docs-page>"` executes code blocks in a named session reusing previously defined variables.
190+
- `result="ansi"` or `result="html"` to render the output. If the code does not produce output, you should leave off the `result` option to prevent an empty cell from rendering in the docs.
191+
192+
For example:
193+
194+
````md
195+
```python exec="true" session="contributing" source="above" result="ansi"
196+
print("Hello world")
197+
```
198+
````
199+
200+
renders as:
201+
202+
```python exec="true" session="contributing" source="above" result="ansi"
203+
print("Hello world")
204+
```
205+
206+
#### Building documentation without executing code blocks
207+
208+
Sometimes, you may want the documentation to build quicker. You can disable code block execution by commenting out the [markdown-exec](https://github.com/zarr-developers/zarr-python/blob/884a8c91afcc3efe28b3da952be3b85125c453cb/mkdocs.yml#L132 plugin in the mkdocs configuration file). This will make code blocks and cross references render incorrectly (i.e., expect build warnings), but also reduces build time by ~3x. Be sure to undo the commenting out before opening your pull request.
209+
176210
### Changelog
177211

178212
zarr-python uses [towncrier](https://towncrier.readthedocs.io/en/stable/tutorial.html) to manage release notes. Most pull requests should include at least one news fragment describing the changes. To add a release note, you'll need the GitHub issue or pull request number and the type of your change (`feature`, `bugfix`, `doc`, `removal`, `misc`). With that, run `towncrier create` with your development environment, which will prompt you for the issue number, change type, and the news text:

0 commit comments

Comments
 (0)