Skip to content

Commit 744186e

Browse files
authored
Merge pull request #1661 from plone/sphinx-examples
Add Sphinx examples extension
2 parents 803d68e + 5105409 commit 744186e

File tree

7 files changed

+38
-134
lines changed

7 files changed

+38
-134
lines changed

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"sphinx.ext.todo",
5050
"sphinx_copybutton",
5151
"sphinx_design",
52+
"sphinx_examples",
5253
"sphinx_reredirects",
5354
"sphinx_sitemap",
5455
"sphinxcontrib.httpdomain", # plone.restapi

docs/contributing/documentation/authors.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,10 @@ When authors add a link to the documentation, it must be a valid public URL with
127127

128128
If it is not a valid link, or is private or local, then you must exclude it from `linkcheck` by wrapping it in single backticks.
129129

130-
```md
130+
```{example}
131131
Visit the URL `http://www.example.com` for an example.
132132
```
133133

134-
This will render as follows.
135-
136-
> Visit the URL `http://www.example.com` for an example.
137-
138134
If a link has succumbed to bit rot, then try finding the most recently scraped version on the [Internet Archive Wayback Machine](https://web.archive.org/), and update the link.
139135

140136
To validate links, run the following command.
@@ -240,6 +236,8 @@ Authors should include at least `description`, `property=og:description`, `prope
240236
The following is an example of `html_meta`.
241237
Note that the content of the two tags `description` and `property=og:description` should be identical.
242238

239+
% Cannot use sphinx-examples for this one.
240+
243241
```md
244242
---
245243
myst:

docs/contributing/documentation/myst-reference.md

Lines changed: 24 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ Official MyST documentation
4747

4848
#### Link to a chapter or page
4949

50-
```md
50+
```{example}
5151
Here is how to set up and build the documentation locally {doc}`/contributing/documentation/setup-build`.
5252
```
5353

54-
Here is how to set up and build the documentation locally {doc}`/contributing/documentation/setup-build`.
55-
5654

5755
(myst-reference-link-heading-label)=
5856

5957
#### Link to a heading
6058

59+
% Headings cannot be nested in sphinx-examples
60+
6161
```md
6262
(myst-reference-hello-heading-label)=
6363

@@ -75,29 +75,21 @@ Read the section {ref}`myst-reference-hello-heading-label`.
7575

7676
#### Link to an arbitrary location
7777

78-
```md
78+
```{example}
7979
(example-target-label)=
8080
8181
I have an HTML anchor above me.
8282
8383
Click the link to visit {ref}`my text <example-target-label>`.
8484
```
8585

86-
(example-target-label)=
87-
88-
I have an HTML anchor above me.
89-
90-
Click the link to visit {ref}`my text <example-target-label>`.
91-
9286

9387
#### Link to external page
9488

95-
```md
89+
```{example}
9690
Use [Shimmer](http://example.com) for cleaner whiter teeth.
9791
```
9892

99-
Use [Shimmer](http://example.com) for cleaner whiter teeth.
100-
10193

10294
### Images and figures
10395

@@ -140,7 +132,7 @@ Cards allow the display of a caption, create a link to the source image to displ
140132

141133
The following MyST example will display as shown below.
142134

143-
`````md
135+
`````{example}
144136
````{card}
145137
```{image} /_static/caching/caching-disabled.png
146138
:alt: Caching Control Panel
@@ -151,15 +143,6 @@ _Caching Control Panel_
151143
````
152144
`````
153145

154-
````{card}
155-
```{image} /_static/caching/caching-disabled.png
156-
:alt: Caching Control Panel
157-
:target: /_static/caching/caching-disabled.png
158-
```
159-
+++
160-
_Caching Control Panel_
161-
````
162-
163146

164147
#### Accessibility with `alt` text
165148

@@ -174,37 +157,31 @@ Accessibility is part of the [Plone brand and identity](https://plone.org/access
174157

175158
The following MyST example will display as shown below.
176159

177-
````md
160+
````{example}
178161
```{image} /_static/standards.png
179162
:alt: XKCD "Standards" comic strip
180163
```
181164
````
182165

183-
```{image} /_static/standards.png
184-
:alt: XKCD "Standards" comic strip
185-
```
186-
187166

188167
#### Inline images
189168

190169
For inline images, we use the MyST extension [`html_image`](https://myst-parser.readthedocs.io/en/latest/syntax/optional.html#html-images).
170+
The HTML attribute `class` must be set to `inline` to render the image inline at `1rem`.
171+
Images and figures should always include `alt` text.
191172
Example syntax is shown below.
192173

193174
```html
194175
You can copy <img alt="Copy icon" src="../../_images/copy.svg" class="inline"> blocks.
195176
```
196177

197-
Note that the HTML attribute `class` must be set to `inline` to render the image inline at `1rem`.
198-
199-
The above syntax renders as shown below.
200-
201178
> You can copy <img alt="Copy icon" src="/_static/copy.svg" class="inline"> blocks.
202179
203-
Images and figures should always include `alt` text.
180+
#### Figure example
204181

205-
The following MyST example will display as shown below.
182+
The following MyST example for `figure` will display as shown below.
206183

207-
````md
184+
````{example}
208185
```{eval-rst}
209186
.. figure:: /_static/voting_flowchart.png
210187
:alt: Voting flowchart
@@ -224,24 +201,6 @@ The following MyST example will display as shown below.
224201
```
225202
````
226203

227-
```{eval-rst}
228-
.. figure:: /_static/voting_flowchart.png
229-
:alt: Voting flowchart
230-
231-
This is a caption in a single paragraph.
232-
233-
This is a legend, which consists of all elements after the caption.
234-
It can include a table.
235-
236-
====== =======
237-
Symbol Meaning
238-
====== =======
239-
⃞ Object
240-
⬭ View
241-
➞ Flow
242-
====== =======
243-
```
244-
245204

246205
### Video
247206

@@ -255,23 +214,18 @@ If you include audio, it is helpful to include closed captions or a transcript.
255214
It is helpful to include overlays of key strokes, and mouse and other input gestures, to describe how to interact with the user interface.
256215

257216
Paths to videos must resolve in both the main documentation and the submodule's documentation, if present.
217+
Note that the path must be absolute to support both submodules and the main documentation.
218+
Don't use file-relative paths.
258219
See {ref}`static-assets-label` for details.
259220

260221
Example MyST syntax is shown below.
261222

262-
````md
263-
```{video} /_static/user-manual/blocks/block-copy-cut.mp4
264-
```
265-
````
266-
267-
Note that the path must be absolute to support both submodules and the main documentation.
268-
Don't use file-relative paths.
269-
The above MyST markup renders as shown below.
270-
223+
`````{example}
271224
````{only} not text
272225
```{video} /_static/user-manual/blocks/block-copy-cut.mp4
273226
```
274227
````
228+
`````
275229

276230

277231
### Diagrams and graphs with Graphviz
@@ -280,7 +234,7 @@ We use [Graphviz](https://graphviz.org/download/) and its Sphinx extension [`sph
280234

281235
The following MyST example will display as shown below.
282236

283-
````markdown
237+
````{example}
284238
```{eval-rst}
285239
.. graphviz::
286240
:align: center
@@ -294,40 +248,22 @@ The following MyST example will display as shown below.
294248
```
295249
````
296250

297-
```{eval-rst}
298-
.. graphviz::
299-
:align: center
300-
301-
digraph viewstructure {
302-
{
303-
node [margin=5,shape=box]
304-
}
305-
ZCML -> {Python, Template};
306-
}
307-
```
308-
309251

310252
### Code block
311253

312254
A Python code snippet without reStructuredText options, using a simple fence.
313255

314-
````md
256+
````{example}
315257
```python
316258
a = 2
317259
print("my 1st line")
318260
print(f"my {a}nd line")
319261
```
320262
````
321263

322-
```python
323-
a = 2
324-
print("my 1st line")
325-
print(f"my {a}nd line")
326-
```
327-
328264
A Python code snippet with reStructuredText options, using a fence with the parsed reStructuredText directive `code-block`.
329265

330-
````md
266+
````{example}
331267
```{code-block} python
332268
:linenos:
333269
:emphasize-lines: 1, 3
@@ -338,28 +274,20 @@ print(f"my {a}nd line")
338274
```
339275
````
340276

341-
```{code-block} python
342-
:linenos:
343-
:emphasize-lines: 1, 3
344-
345-
a = 2
346-
print("my 1st line")
347-
print(f"my {a}nd line")
348-
```
349277

350278
### Escape literal backticks inline
351279

352-
```md
280+
```{example}
353281
This is MyST syntax for term ``{term}`React` ``
354282
```
355283

356-
This is MyST syntax for term ``{term}`React` ``
357-
358284

359285
### Glossary terms
360286

361287
Add a term to the {ref}`glossary-label`, located at {file}`/glossary.md`.
362288

289+
% For sphinx-examples, do not add a glossary term, as it will conflict with that in the actual glossary.
290+
363291
```md
364292
React
365293
[React](https://reactjs.org/) is a JavaScript library for building user interfaces.
@@ -368,18 +296,16 @@ React
368296

369297
Reference a term in the {ref}`glossary-label`.
370298

371-
```md
299+
```{example}
372300
Using {term}`React` makes frontends fun again!
373301
```
374302

375-
Using {term}`React` makes frontends fun again!
376-
377303

378304
### Nesting directives
379305

380306
You can [nest directives](https://myst-parser.readthedocs.io/en/latest/syntax/roles-and-directives.html#nesting-directives), such as [admonitions](https://myst-parser.readthedocs.io/en/latest/syntax/admonitions.html) and code blocks, by ensuring that the backtick-lines corresponding to the outermost directive are longer than the backtick-lines for the inner directives.
381307

382-
`````
308+
`````{example}
383309
````{tip}
384310
To use formatted string literals ("f-strings"), begin a string with `f` or `F` before the opening quotation mark or triple quotation mark.
385311
Inside this string, you can write a Python expression between `{` and `}` characters that can refer to variables or literal values.
@@ -394,19 +320,3 @@ print(f"my {a}nd line")
394320
```
395321
````
396322
`````
397-
398-
This would be rendered as:
399-
400-
````{tip}
401-
To use formatted string literals ("f-strings"), begin a string with `f` or `F` before the opening quotation mark or triple quotation mark.
402-
Inside this string, you can write a Python expression between `{` and `}` characters that can refer to variables or literal values.
403-
404-
```{code-block} python
405-
:linenos:
406-
:emphasize-lines: 1, 3
407-
408-
a = 2
409-
print("my 1st line")
410-
print(f"my {a}nd line")
411-
```
412-
````

docs/contributing/documentation/themes-and-extensions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ We use several MyST and Sphinx extensions to enhance the presentation of Plone d
4242

4343
- [`myst_parser`](https://myst-parser.readthedocs.io/en/latest/) parses MyST, a rich and extensible flavour of Markdown for authoring documentation.
4444
- [`sphinx-design`](https://sphinx-design.readthedocs.io/en/latest/), with a configuration name of `sphinx_design`, adds grids, cards, icons, badges, buttons, tabs, and dropdowns.
45+
- [`sphinx-examples`](https://ebp-sphinx-examples.readthedocs.io/en/latest/) adds "example snippets" that allow you to show off source Markdown and the result of rendering it in Sphinx.
4546
- [`sphinx-notfound-page`](https://sphinx-notfound-page.readthedocs.io/en/latest/index.html), with a configuration name of `notfound.extension`, creates a custom 404 page and helps generate proper static resource links to render the page properly.
4647
- [`sphinx.ext.autodoc`](https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html) pulls in documentation from Python docstrings to generate reStructuredText which in turn gets parsed by Sphinx and rendered to the output format.
4748
It is used by {doc}`/plone.api/index`.

docs/glossary.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ fence
344344
You can define a directive with backticks (`` ` ``) followed by a reStructuredText directive in curly brackets (`{}`), and a matching number of closing backticks.
345345
You can also nest fences by increasing the number of backticks.
346346
347-
`````md
347+
`````{example}
348348
````{warning}
349349
There be dragons!
350350
```{important}
@@ -353,13 +353,6 @@ fence
353353
````
354354
`````
355355
356-
````{warning}
357-
There be dragons!
358-
```{important}
359-
Dragons have feelings, too!
360-
```
361-
````
362-
363356
Open Graph
364357
The [Open Graph protocol](https://ogp.me/) enables any web page to become a rich object in a social graph.
365358
For instance, this is used on Facebook to allow any web page to have the same functionality as any other object on Facebook.
@@ -744,7 +737,7 @@ Plone frontend
744737
A frontend consists of the user interface elements of a web application.
745738
Beginning with Plone 6, the default frontend is {term}`Volto`.
746739
{term}`Classic UI` is a secondary frontend that is part of the {term}`Plone backend`.
747-
740+
748741
TLS
749742
Transport Layer Security
750743
Transport Layer Security (TLS) is a cryptographic protocol designed to provide communications security over a computer network.

docs/install/containers/images/index.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ myst:
1111

1212
The Plone community maintains the following official images:
1313

14-
| Image | Description |
15-
| --- | --- |
16-
| [plone/plone-backend](backend) | Plone backend. Could be used standalone or as a headless CMS |
17-
| [plone/plone-frontend](frontend) | Plone default frontend written in React. Requires a Plone backend |
18-
| [plone/plone-zeo](zeo) | ZEO server, a specialized database to be used with Plone backend |
14+
| Image | Description |
15+
|-----------------|-------------------------------------------------------------------|
16+
| {doc}`backend` | Plone backend. Could be used standalone or as a headless CMS |
17+
| {doc}`frontend` | Plone default frontend written in React. Requires a Plone backend |
18+
| {doc}`zeo` | ZEO server, a specialized database to be used with Plone backend |
1919

2020
```{toctree}
2121
:maxdepth: 2

0 commit comments

Comments
 (0)