Contributing documentation¶
Prerequisites¶
Before contributing to EPNix, follow the contributing Prerequisites.
Documentation philosophy¶
Make sure to read the Documentation philosophy, which explains how the documentation is structured and the writing style.
Building documentation¶
As a package¶
To build the documentation, run the following from EPNix’s source code directory:
nix build -L ".#docs"
The HTML is then stored in ./result/share/doc/epnix/html/.
You can open a browser with xdg-open ./result/share/doc/epnix/html/index.html.
Tip
Some features aren’t available when using a web browser with files, such as link icons. If you want the documentation with these features, run:
python -m http.server 8000 -b 127.0.0.1 -d result/share/doc/epnix/html
Then open a browser at http://localhost:8000.
In a development shell¶
When actively writing documentation,
building the epnix.docs package is slow.
You can use the docs development shell
to build the documentation with make:
nix develop ".#docs"
make -C docs html
If there are issues with the sidebar
or other inconsistencies,
run make -C docs clean
then rebuild the documentation.
Tip
For a faster edit and compile cycle, you can use the watchexec tool to automatically build the documentation when you change files:
# If not already,
# enter the "docs" development shell
nix develop ".#docs"
# Leave this command running in a terminal
watchexec "make -C docs html"
You can open a browser with xdg-open docs/_build/html/index.html
or run a web server with:
python -m http.server 8000 -b 127.0.0.1 -d docs/_build/html
This command starts a web server available at http://localhost:8000.
Writing style¶
Read Writing style in the Documentation philosophy article for general guidelines.
Vale¶
We recommend using Vale when writing documentation.
To install it as a command-line tool, follow Vale’s Install instructions. To install it as a Language Server, follow Vale’s LSP guide.
When writing, try to follow Vale’s advice when it makes sense.
Following every Vale rule isn’t mandatory, but it should lead to better documentation.
Sphinx and MyST’s Markdown¶
EPNix uses Sphinx as a documentation system and the MyST Sphinx extension to write it in Markdown.
MyST’s Markdown differs in some ways from the standard Markdown format to offer Sphinx’s features.
Read Sphinx’s documentation to learn more about the framework, features, plugins, or how to organize documents.
Read MyST’s documentation to learn about the Markdown syntax.
The following is a summary of some features.
Organizing the structure¶
Sphinx builds a tree of documents
called a “TOC tree.”
You use the toctree directive
to insert child documents.
For example:
```{toctree}
:maxdepth: 2
sub-document
```
Some recommendations:
Use the
```{toctree}Markdown syntax, not:::{toctree}.Use the
:maxdepth: 2option.Use the
:glob:option and*as document when the general order doesn’t matter.Tip
You can mix globbing and selecting articles to put first or last, for example:
Order a single article as first¶```{toctree} :glob: :maxdepth: 2 prerequisites * ```Use the
:numbered:option when you want to sequence a set of articles, such as for tutorials.
Code blocks¶
Use the code-block directive.
Use the :caption: option
to describe your code extract.
For example:
```{code-block} nix
:caption: An example Nix attribute set
{
example = "Hello, world!";
}
```
Figures¶
Use the figure directive,
for example:
```{figure} my-article/my-image.png
An example image description
```
Links¶
Cross-referencing must be done in a future-proof way, meaning that if possible, if a link breaks, Sphinx should output a warning during the build.
For this, use Sphinx’s roles to express which type of object you’re referencing.
To other articles¶
To link to another EPNix article,
use the doc role.
For example:
See the {doc}`../guides/prerequisites`.
Try to keep the title of the article in the text. If necessary, you can change the link title with this syntax:
See the {doc}`custom title <../guides/prerequisites>`.
To a sub-section¶
In the same document¶
To link to a sub-section in the same article, you can use MyST’s implicit targets feature:
## A heading with slug
See the section <project:#a-heading-with-slug>
Try to keep the original title in the text. If necessary, you can change the link title with this syntax:
## A heading with slug
See the section [custom title](#a-heading-with-slug)
In another document¶
Create an explicit target:
*In the target article:*
(my-target-name)=
## Document subsection
----
*Then, in the other article*
See the section {ref}`my-target-name`.
Important
The name of your target must be a unique “ref” throughout the entire EPNix documentation.
Tip
This explicit target syntax also works for paragraphs and other elements.
To a code block, figure, or table¶
To link to a code block, figure, or table,
use the :name: option:
```{figure} my-article/my-image.png
:name: my-figure
An example image description
```
----
See the {ref}`my-figure` figure.
Important
The name of your target must be a unique “ref” throughout the entire EPNix documentation.
To a NixOS option¶
To link to NixOS options,
use the nix:option role:
Use the {nix:option}`services.archiver-appliance.enable` option.
To a Nix package¶
To link to a Nix package,
use the nix:pkg role:
Install the {nix:pkg}`epnix.epics-base` package.
To EPNix’s source code¶
Use the source MyST URL scheme to link to a file or directory
in EPNix’s source code:
See the <source:docs> folder.
To other Sphinx-based documentation¶
Use Sphinx’s Intersphinx extension to link to other articles or elements of another Sphinx-based documentation.
If missing,
add the other documentation
to the intersphinx_mapping option
in docs/conf.py.
Once done,
any cross-referencing role,
except doc,
can resolve to an external document.
For example:
- {rst:dir}`toctree` resolves to the Sphinx documentation
- {cpp:class}`epicsThread` resolves to the `epics-base` documentation
Gives the following result:
toctreeresolves to the Sphinx documentationepicsThreadresolves to theepics-basedocumentation
Tip
In the docs development shell,
you can run this to show available objects:
python -m sphinx.ext.intersphinx $URL/objects.inv
# For example:
python -m sphinx.ext.intersphinx https://www.sphinx-doc.org/en/master/objects.inv
If you want to link explicitly to a given project
or if you want to use the doc,
prefix your role with external+project:.
For example:
- {external+sphinx:doc}`usage/restructuredtext/roles` resolves to the Sphinx documentation
- {external+myst:ref}`syntax/implicit-targets` resolves to the MyST documentation
- {external+epics-base:cpp:class}`epicsThread` resolves to the `epics-base` documentation
Gives the following result:
Roles resolves to the Sphinx documentation
Implicit targets resolves to the MyST documentation
epicsThreadresolves to theepics-basedocumentation