Skip to content

docs: render docstring examples as code in the API reference (#1128) - #1129

Merged
jepegit merged 1 commit into
masterfrom
cursor/1128-docs-example-widget-0881
Oct 1, 2026
Merged

jepegit merged 1 commit into
masterfrom
cursor/1128-docs-example-widget-0881

Conversation

@jepegit

@jepegit jepegit commented Oct 1, 2026

Copy link
Copy Markdown
Owner

Closes #1128

Root cause

griffe's Google-style parser (griffelib 2.1.0, _section_kind) only recognises the plural Examples: section title. Eleven docstrings in src/cellpy used Example:, which falls through to a generic admonition whose body mkdocstrings renders as markdown. A line starting with >>> is three nested markdown blockquotes — the three vertical bars in the issue screenshot — and the code becomes plain paragraph text with the prompts eaten. A local zensical build reproduced it exactly (<details class="example"><blockquote><blockquote><blockquote>…).

The same screenshot shows a second format bug: the list_templates Returns: description wrapped at the same indent as its first line, so griffe split it into four dict items.

Fix (docstring level, as the issue preferred)

  • Rename all 11 Example: → Examples: (cli_api.py, ica.py ×3, collect/ica.py, collect/dva.py, readers/cellreader.py ×2, parameters/internal_settings.py, batch/facade.py, readers/instruments/base.py).
  • The two prose examples (Batch.load, BaseLoader.get_raw_units) switch from RST :: literal blocks to fenced ```python so they highlight under Examples:.
  • list_templates Returns: continuation lines indented → one item.
  • New tests/test_docstring_sections.py (essential, stdlib ast, <1 s): fails with file:line on any bare Example: title in src/cellpy. On master it lists all 11 offenders; here it passes. Registry row added.
  • No theme / template / CSS override.

Before / after

Before (from the issue):

Before: nested blockquotes, plain text, four dict return items

After (rebuilt locally, site/api/cellpy/):

After: single Returns item and highlighted pycon Examples block

How to test

  • uv run pytest tests/test_docstring_sections.py — passes; git stash -- src and rerun to see it fail on the 11 old titles.
  • uv run --group docs zensical build --clean → No issues found; rg -c '<details class="example"' site/api → no hits (was 4 API pages).
  • uv run .issueflows/00-tools/check_docs_relative_links.py → all resolve.
  • MPLBACKEND=Agg uv run pytest -m essential → 982 passed, 74 skipped; the 2 test_filefinder.py::test_find_by_project_* failures are the same VM-only ones that also fail on a stashed origin/master here while master CI is green.

To show artifacts inline, enable in settings.

Open in Web Open in Cursor 

griffe's Google-style parser only recognises the plural "Examples:" section
title. Eleven docstrings used "Example:", which fell through to a generic
admonition rendered as markdown, so the ">>>" prompts became three nested
blockquotes (the vertical bars in the issue screenshot) and the code lost
its highlighting. Rename them all to "Examples:"; the two prose examples
(Batch.load, BaseLoader.get_raw_units) switch from RST "::" literal blocks
to fenced python blocks so they highlight too. The list_templates return
description now indents its continuation lines so griffe reads one item
instead of four.

Add tests/test_docstring_sections.py (essential): an ast scan of src/cellpy
docstrings that fails with file:line on any new singular "Example:" title.

Closes #1128

Co-authored-by: Jan Petter Maehlen <jepe@ife.no>
@jepegit
jepegit marked this pull request as ready for review October 1, 2026 18:29
@jepegit
jepegit merged commit 7aea3d9 into master Oct 1, 2026
6 checks passed
@jepegit
jepegit deleted the cursor/1128-docs-example-widget-0881 branch October 1, 2026 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Docs example widget looks bad

2 participants