Directives¶
Directives are the block-level building blocks of reStructuredText —
each one starts with .. name:: and can take an argument, options, and a body.
The ubCode preview renders a known set of core directives richly
(as real boxes, images, and blocks),
and renders every other directive as a readable generic placeholder
that still shows the directive’s name, its options, and its body.
This reference describes the Rendered preview mode;
in Structural mode every directive renders as a uniform placeholder
(see Preview modes).
Where the preview differs from a full sphinx-build,
this page adds a short note and points to Differences from a Sphinx build,
which owns the complete register.
Need directives are covered in Needs;
the diagram directives (mermaid, uml, and plantuml)
are covered in Diagrams,
and sphinx-design’s grids, cards, dropdowns, tabs and buttons in Layout components.
These families of directives each have a page of their own, with a live specimen of every directive in the family, in reStructuredText and in MyST:
Admonitions — notes, tips, warnings, and boxes with a title of your own.
Code and includes — code blocks, literal includes, parsed literal blocks, and files spliced into the page.
Images, figures and video — images, figures, and embedded videos.
Version markers — the added, changed, deprecated and removed markers.
Glossary, index, confval and envvar — glossary terms, index entries, configuration values and environment variables, with the roles that link to them.
Structure and layout — rubrics, columns, grouping blocks, topics, sidebars, and a table of contents for the page.
Conditional content — content for one build only, and the
ifandchoosevariant conditions.Page state — directives that change the page rather than add to it, such as the default role and the highlight language.
Math — formulas set on a line of their own, and inside a sentence.
Todos — outstanding tasks, and the list that gathers them.
The sections below cover the directives that have no family page yet.
The generic placeholder¶
Any directive not listed on this page or on one of its family pages renders as a generic placeholder: a labelled block showing the directive’s name, a table of the options you gave it, and its body. Crucially, the body content is still rendered as markup — paragraphs, lists, inline formatting, and nested directives inside a placeholder all render normally; only the directive’s own special behaviour is missing.
The one well-known directive that currently renders this way is the remaining
Sphinx-Needs generative directive, needservice:
the placeholder shows the options you wrote,
but producing its final form needs machinery ubCode does not ship yet.
The needs view directives — needlist, needtable, needflow,
needsequence, needpie, needbar and needgantt — do render their
real output,
as does needreport, which reports on the project’s own types, links and
fields.
needuml and needarch render their real output as well:
their body is a Jinja template, rendered against the project’s needs into a
diagram that the page draws.
needextract renders its real output too:
it shows the needs you select as ordinary need cards,
with their current metadata and their body,
at the place you wrote the directive.
It is a view, not a copy —
it creates no new need,
and it does not repeat the anchors of the needs it shows,
so a link to a need always lands on the page that defines it.
See Differences from a Sphinx build for the anchor policy in full
and for what an extracted need’s body may contain.
list2need creates its needs: each bullet becomes a real need in the
index, so it can be filtered, linked to and jumped to like any other,
and :presentation: lays the cards out
(see Needs from a list).
See Differences from a Sphinx build for what differs from a Sphinx build.
Syntax examples¶
The syntax-example directive shows a block of markup twice —
once as its raw, highlighted source, and once as the rendered result of parsing that source.
It is meant for documentation that teaches a markup syntax,
where the reader needs to see both what to type and what it produces.
This directive comes from the third-party
sphinx-syntax-example package
(module name sphinx_syntax_example);
install it to use the directive in a full sphinx-build.
The preview implements it natively, with nothing to install —
it only needs that module name listed
in your parsing configuration:
[parse]
extensions = ["sphinx_syntax_example"]
The optional argument is a title shown above the block (Example when omitted),
and the :highlight: option sets the source language.
When :highlight: is omitted the language follows the document’s configured format
(the parser chosen for its source suffix), not a guess from the file name:
rst for reStructuredText sources, and markdown for Markdown sources
(a full sphinx-build prefers a myst lexer for Markdown when one is registered,
while ubCode always uses markdown;
pass :highlight: myst explicitly to use ubCode’s own MyST grammar,
the same one both builders and the preview draw MyST with).
An unknown :highlight: value falls back to the inferred language rather than failing the build.
Because the content is rendered as real nested markup rather than reassembled text,
an example may itself contain code blocks, backticks, or nested directives without any escaping.
The syntax_example_numbering key (see Parsing) numbers each document’s examples —
Example N without a title argument, Example N: <title> with one,
counting from 1 again in every document,
and continuing across an .. include:: rather than restarting in the fragment.
It is off by default, which keeps the plain titles described above,
and it needs sphinx-syntax-example 0.2.0 or later to match in a full sphinx-build.
Inline markup in the title argument is a known divergence:
a full sphinx-build parses it, while the preview shows the title as plain text,
so *nice* stays literal.
Every specimen in this reference is a syntax-example,
so this one shows a syntax-example inside another:
the outer example’s result is the inner example, source and result.
A syntax example
.. syntax-example:: A note
Use a ``note`` admonition for **supplementary** information.
.. note::
This box is rendered from the source shown above.
A note
Use a ``note`` admonition for **supplementary** information.
.. note::
This box is rendered from the source shown above.
Use a note admonition for supplementary information.
Note
This box is rendered from the source shown above.
````{syntax-example} A note
Use a `note` admonition for **supplementary** information.
```{note}
This box is rendered from the source shown above.
```
````
The MyST form renders live in the MyST syntax example.
See also
Roles — the inline roles the preview understands.
Needs — need directives.
Diagrams — the
mermaid,uml, andplantumldirectives.Differences from a Sphinx build — the full register of preview versus build differences.
Parsing — teach the parser new directive names with
extend_directives, or silence unknown-directive warnings withignore_directives.Linting — how unknown-directive warnings are configured.