Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add info on how to cross-reference gallery examples #534

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/developers/contributing/documentation/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -577,3 +577,10 @@ is not necessary—you can copy-paste the code above it. However, it is required
Because our example gallery is built from Python scripts, you need to ensure this
block is present in all contributed examples.
````

### Cross-referencing Gallery examples

If you want to generate links to Gallery examples from anywhere in the docs, then the cross-referencing format you use will depend on the format of the doc you are writing. Note that the gallery examples live in `/gallery` despite being in `napari/examples` because [`docs/docs/conf.py`](https://github.com/napari/docs/blob/main/docs/conf.py) specificies that examples are built into the `gallery` directory. The [Sphinx cross-reference namespace](https://sphinx-gallery.github.io/stable/advanced.html#know-your-gallery-files) is generated with the `sphx_glr` prefix, then path separators are converted to underscores, for example `/gallery/add_image.py` becomes `_gallery_add_image.py` to get the end result `sphx_glr_gallery_add_image.py`.

- For `.md` files (myst, used in the majority of docs), use the `{ref}` directive. ``{ref}`sphx_glr_gallery_add_image.py` `` displays as: {ref}`sphx_glr_gallery_add_image.py`
- For `.py` files (rst, used in the example gallery), cross-reference with the `:ref:` directive: `` :ref:`sphx_glr_gallery_example.py` ``.
Loading