Skip to content

Commit a16787b

Browse files
committed
Update docs with general gated syntax
1 parent ee6720b commit a16787b

File tree

1 file changed

+51
-6
lines changed

1 file changed

+51
-6
lines changed

docs/source/syntax.md

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,60 @@ factorial(4)
140140
_Source:_ [QuantEcon](https://python-programming.quantecon.org/functions.html#Exercise-1)
141141

142142

143-
### Alternative Gated Solution Syntax (Code Execution Support)
143+
## Alternative Gated Syntax
144144

145-
A limitation of MyST is that `code-cell` directives must be at the root level of the document for them to be executed. This maintains direct
146-
compatility with the `jupyter notebook` and enables tools like `jupytext` to convert between `myst` and `ipynb` files. As a result **executable**
147-
`code-cell` directives cannot be nested inside of a solution block.
145+
A restriction of MyST is that `code-cell` directives must be at the root level of the document for them to be executed. This maintains direct
146+
compatility with the `jupyter notebook` and enables tools like `jupytext` to convert between `myst` and `ipynb` files.
148147

149-
The solution to this is to use the **gated solution syntax**.
148+
As a result **executable** `code-cell` directives cannot be nested inside of exercises or solution directives.
150149

151-
#### Example
150+
The solution to this is to use the **gated syntax**.
151+
152+
```{note}
153+
This syntax can also be a convenient way of surrounding blocks of text that may include other directives that you wish
154+
to include in an exercise or solution admonition.
155+
```
156+
157+
### Basic Syntax
158+
159+
````md
160+
```{exercise-start}
161+
:label: ex1
162+
```
163+
164+
```{code-cell}
165+
# Some setup code that needs executing
166+
```
167+
168+
and maybe you wish to add a figure
169+
170+
```{figure} img/example.png
171+
```
172+
173+
```{exercise-end}
174+
```
175+
````
176+
177+
The `exercise-start` directive allows for he same options as core `exercise` directive.
178+
179+
````md
180+
```{solution-start} ex1
181+
```
182+
183+
```{code-cell}
184+
# Solution Code
185+
```
186+
187+
```{solution-end}
188+
```
189+
````
190+
191+
```{warning}
192+
If there are missing `-start` and `-end` directives, this will cause Sphinx to return an extension error,
193+
alongside some helpful feedback to diagnose the issue in document structure.
194+
```
195+
196+
### Example
152197

153198
````md
154199

0 commit comments

Comments
 (0)