Skip to content

Commit 8a75b0e

Browse files
committed
Fix rendering of examples
1 parent 0a307c6 commit 8a75b0e

File tree

3 files changed

+66
-16
lines changed

3 files changed

+66
-16
lines changed

sphinxdocs/docs/sphinx-bzl.md

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,11 @@ The documentation renders using RST notation (`.. directive::`), not
227227
MyST notation.
228228
:::
229229

230+
Directives can be nested, but [the inner directives must have **fewer** colons
231+
than outer
232+
directives](https://myst-parser.readthedocs.io/en/latest/syntax/roles-and-directives.html#nesting-directives).
233+
234+
230235
:::{rst:directive} .. bzl:currentfile:: file
231236

232237
This directive indicates the Bazel file that objects defined in the current
@@ -237,46 +242,85 @@ files, and `//foo:BUILD.bazel` for things in BUILD files.
237242
:::
238243

239244

240-
:::{rst:directive} .. bzl:target:: target
245+
:::::{rst:directive} .. bzl:target:: target
241246

242247
Documents a target. It takes no directive options. The format of `target`
243248
can either be a fully qualified label (`//foo:bar`), or the base target name
244249
relative to `{bzl:currentfile}`.
245250

246-
```
251+
````
247252
:::{bzl:target} //foo:target
248253
249254
My docs
250255
:::
251-
```
256+
````
257+
258+
:::::
252259

253260
:::{rst:directive} .. bzl:flag:: target
254261

255262
Documents a flag. It has the same format as `{bzl:target}`
256263
:::
257264

265+
::::::{rst:directive} .. bzl:typedef:: typename
258266

259-
:::{rst:directive} .. bzl:typedef:: typename
267+
Documents a user-defined structural "type". These are typically generated by
268+
the {obj}`sphinx_stardoc` rule after following [User-defined types] to create a
269+
struct with a `TYPEDEF` field, but can also be manually defined if there's
270+
no natural place for it in code, e.g. some ad-hoc structural type.
260271

261-
Documents a user-defined structural "type". These are typically generated
262-
by following [User-defined types] to create a struct with a `TYPEDEF` field.
263-
264-
```
272+
`````
265273
::::{bzl:typedef} Square
274+
Doc about Square
266275
267276
:::{bzl:field} width
268277
:type: int
269278
:::
270279
271280
:::{bzl:function} new(size)
281+
...
272282
:::
273283
274284
:::{bzl:function} area()
285+
...
275286
:::
276287
::::
277-
```
288+
`````
278289

279-
Note that, due to a Sphinx and/or MyST bug, the number of colons for the
280-
outer typedef directive must be greater than the inner directives. Otherwise,
281-
only the first nested directive is parsed as part of the type def.
282-
:::
290+
Note that MyST requires the number of colons for the outer typedef directive
291+
to be greater than the inner directives. Otherwise, only the first nested
292+
directive is parsed as part of the typedef, but subsequent ones are not.
293+
::::::
294+
295+
:::::{rst:directive} .. bzl:field:: fieldname
296+
297+
Documents a field of an object. These are nested within some other directive,
298+
typically `{bzl:typedef}`
299+
300+
Directive options:
301+
* `:type:` specifies the type of the field
302+
303+
````
304+
:::{bzl:field} fieldname
305+
:type: int | None | str
306+
307+
Doc about field
308+
````
309+
:::::
310+
311+
:::::{rst:directive} .. bzl:provider-field:: fieldname
312+
313+
Documents a field of a provider. The directive itself is autogenerated by
314+
`sphinx_stardoc`, but the content is simply the documentation string specified
315+
in the provider's field.
316+
317+
Directive options:
318+
* `:type:` specifies the type of the field
319+
320+
````
321+
:::{bzl:provider-field} fieldname
322+
:type: depset[File] | None
323+
324+
Doc about the provider field
325+
````
326+
:::::

sphinxdocs/docs/starlark-docgen.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ using the {rst:directive}`bzl:typedef` directive and puts all the struct's field
8585
within the typedef. The net result is the rendered docs look similar to how
8686
a class would be documented in other programming languages.
8787

88-
For example, a `Square` object with a `area()` method would look like:
88+
For example, a the Starlark implemenation of a `Square` object with a `area()`
89+
method would look like:
8990

9091
```
9192
@@ -133,16 +134,19 @@ A square with fixed size
133134
:type: int
134135
:::
135136
:::{bzl:function} new()
136-
...
137+
...args etc from _Square_new...
137138
:::
138139
:::{bzl:function} area()
139-
...
140+
...args etc from _Square_area...
140141
:::
141142
::::
142143
```
143144

144145
Which renders as:
145146

147+
:::{bzl:currentfile} //example:square.bzl
148+
:::
149+
146150
::::{bzl:typedef} Square
147151
A square with fixed size
148152

sphinxdocs/src/sphinx_bzl/bzl.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,7 @@ class _BzlTypedef(_BzlObject):
825825
826826
A typedef describes objects with well known attributes.
827827
828+
`````
828829
::::{bzl:typedef} Square
829830
830831
:::{bzl:field} width
@@ -837,6 +838,7 @@ class _BzlTypedef(_BzlObject):
837838
:::{bzl:function} area()
838839
:::
839840
::::
841+
`````
840842
"""
841843

842844

0 commit comments

Comments
 (0)