Skip to content

Commit 1de6612

Browse files
committed
docs: Show real sources in gallery
1 parent daba198 commit 1de6612

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

docs/gallery.md

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ as base64 encoded PNG data. Finally we output an HTML image with the base64 data
1919
Using SVG is not possible here since Diagrams embeds actual, smaller PNG files
2020
in the result, files which are not automatically added to the final site.
2121

22-
```python exec="true" html="true" source="tabbed-right" title="Diagrams"
22+
````md exec="1" source="tabbed-right" title="Diagrams"
23+
```python exec="true" html="true"
2324
--8<-- "gallery/diagrams.py"
2425
```
26+
````
2527

2628
## Python dependency tree
2729

@@ -34,16 +36,16 @@ from our own package.
3436
````md exec="1" source="tabbed-right" title="pipdeptree mermaid diagram"
3537
```bash exec="1" result="mermaid"
3638
pipdeptree -p markdown-exec --mermaid 2>/dev/null |
37-
sed 's/flowchart TD/flowchart LR/' |
38-
sed 's/\.dev.+"\]$/"]/;s/\+d.*"\]$/"]/'
39+
sed -E 's/\.dev.+"\]$/"]/;s/\+d.*"\]$/"]/'
3940
```
4041
````
4142

42-
Another example with more dependencies and top-down direction:
43+
Another example with more dependencies:
4344

4445
````md exec="1" source="tabbed-right" title="pipdeptree mermaid diagram"
4546
```bash exec="1" result="mermaid"
46-
pipdeptree -p mkdocstrings-python --mermaid 2>/dev/null
47+
pipdeptree -p mkdocstrings-python --mermaid 2>/dev/null |
48+
sed 's/flowchart TD/flowchart LR/'
4749
```
4850
````
4951

@@ -60,9 +62,11 @@ so the code is a bit convoluted, but you could make a function of it,
6062
put it in an importable script/module, and reuse it cleanly in your executed
6163
code blocks.
6264

63-
```python exec="true" html="true" source="tabbed-right" title="pydeps module dependencies graph"
65+
````md exec="1" source="tabbed-right" title="pydeps module dependencies graph"
66+
```python exec="true" html="true"
6467
--8<-- "gallery/pydeps.py"
6568
```
69+
````
6670

6771
## Code snippets
6872

@@ -73,9 +77,11 @@ from somewhere else using the
7377
or by reading it dynamically from Python.
7478
We also prevent Rich from actually writing to the terminal.
7579

76-
```python exec="true" html="true" source="tabbed-right" title="Rich SVG code snippet"
80+
````md exec="1" source="tabbed-right" title="Rich SVG code snippet"
81+
```python exec="true" html="true"
7782
--8<-- "gallery/rich.py"
7883
```
84+
````
7985

8086
<!--
8187
Similarly, [PyTermGUI](https://github.com/bczsalba/pytermgui) also allows
@@ -100,43 +106,53 @@ allowing to render them naturally in your documentation pages.
100106
For this to happen, use the
101107
[`result="ansi"` option](http://localhost:8000/markdown-exec/usage/#wrap-result-in-a-code-block).
102108

103-
```bash exec="true" source="tabbed-right" title="ANSI terminal output" result="ansi"
109+
````md exec="1" source="tabbed-right" title="ANSI terminal output"
110+
```bash exec="true" result="ansi"
104111
--8<-- "gallery/ansi.sh"
105112
```
113+
````
106114

107115
As an alternative, we can use Rich again to render the output of a command in a terminal, with colors.
108116
This example is taken directly from the documentation of the [Griffe](https://github.com/mkdocstrings/griffe) project.
109117

110-
```python exec="true" html="true" source="tabbed-right" title="Rich terminal output"
118+
````md exec="1" source="tabbed-right" title="Rich terminal output"
119+
```python exec="true" html="true"
111120
--8<-- "gallery/rich_terminal.py"
112121
```
122+
````
113123

114124
## TUI screenshots
115125

116126
[Textual](https://github.com/Textualize/textual) allows to build Terminal User Interfaces (TUIs).
117127
In this example we generate the SVG image of a terminal interface.
118128

119-
```python exec="1" html="true" source="tabbed-right" tabs="Source|Result"
129+
````md exec="1" source="tabbed-right" title="Textual screenshot"
130+
```python exec="1" html="true"
120131
--8<-- "gallery/textual.py"
121132
```
133+
````
122134

123135
## Charts and Plots
124136

125137
With [Matplotlib](https://matplotlib.org/):
126138

127-
```python exec="1" html="1" source="tabbed-right" title="matplotlib graph"
139+
````md exec="1" source="tabbed-right" title="matplotlib graph"
140+
```python exec="1" html="1"
128141
--8<-- "gallery/matplotlib.py"
129142
```
143+
````
130144

131145
## Python module output
132146

133147
This example uses Python's [`runpy`][runpy] module to run another
134148
Python module. This other module's output is captured by temporarily
135149
patching `sys.stdout` with a text buffer.
136150

137-
```python exec="true" source="tabbed-right" title="runpy and script/module output"
151+
````md exec="1" source="tabbed-right" title="runpy and script/module output"
152+
```python exec="true"
138153
--8<-- "gallery/runpy.py"
139154
```
155+
````
140156

141157
## Python CLI documentation
142158

@@ -147,16 +163,20 @@ if you know the project is using [`argparse`][argparse] to build its command lin
147163
interface, and if it exposes its parser, then you can get the help message
148164
directly from the parser.
149165

150-
```python exec="true" source="tabbed-right" title="argparse parser help message"
166+
````md exec="1" source="tabbed-right" title="argparse parser help message"
167+
```python exec="true"
151168
--8<-- "gallery/argparse_format.py"
152169
```
170+
````
153171

154172
### Argparse parser documentation
155173

156174
In this example, we inspect the `argparse` parser to build better-looking
157175
Markdown/HTML contents. We simply use the description and iterate on options,
158176
but more complex stuff is possible of course.
159177

160-
```python exec="true" source="tabbed-right" updatetoc="no" title="CLI help using argparse parser"
178+
````md exec="1" source="tabbed-right" title="CLI help using argparse parser"
179+
```python exec="true" updatetoc="no"
161180
--8<-- "gallery/argparse.py"
162181
```
182+
````

docs/snippets/gallery/pydeps.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"markdown_exec.formatters.console",
2222
"markdown_exec.formatters.markdown",
2323
"markdown_exec.formatters.pycon",
24+
"markdown_exec.formatters.pyodide",
2425
"markdown_exec.formatters.python",
2526
"markdown_exec.formatters.sh",
2627
"markdown_exec.formatters.tree",

0 commit comments

Comments
 (0)