Writing content

This section is the reference for writing content that ubCode understands, in reStructuredText and in Markdown (MyST): what each construct is written as, what ubCode renders from it — in the editor preview and in its html and pdf builds — and where that differs from a Sphinx build. For the languages themselves, see the Sphinx reStructuredText primer and the directives reference; for the preview panel and its two modes, see RST preview.

Essentials

The constructs most pages are written with. Open one to see it written in both markups, as two tabs, and rendered live by this site’s own build (see reStructuredText and MyST), and follow its link to the page that covers its family in full.

Headings — a title for the page and for each section, and a label to link to it
Page title
==========

.. _a-section:

A section
---------
# Page title

(a-section)=
## A section

More: Sections.

Inline markup — emphasis, strong text and inline code

Inline markup

Text can be *emphasised*, **strong**, or ``code``.

Text can be emphasised, strong, or code.

Text can be *emphasised*, **strong**, or `code`.

The MyST form renders live in the MyST inline markup.

More: Inline markup.

Lists — bullet items, and items numbered for you

Lists

- A bullet item.
- Another.

#. A numbered item.
#. The next.
  • A bullet item.

  • Another.

  1. A numbered item.

  2. The next.

- A bullet item.
- Another.

1. A numbered item.
1. The next.

The MyST form renders live in the MyST lists.

More: Bullet and enumerated lists.

Links — to a web page, and to a label on a heading anywhere in the project

Links

Read `the Sphinx site <https://www.sphinx-doc.org/>`_,
or this page's :ref:`authoring_index_rst_and_myst`.

Read the Sphinx site, or this page’s reStructuredText and MyST.

Read [the Sphinx site](https://www.sphinx-doc.org/),
or this page's {ref}`authoring_index_rst_and_myst`.

The MyST form renders live in the MyST links.

Put the label above a heading, as the Headings entry shows.

More: References and links.

Code blocks — source code, highlighted for its language

Code block

.. code-block:: python

   print("Hello, ubCode!")
print("Hello, ubCode!")
```python
print("Hello, ubCode!")
```

The MyST form renders live in the MyST code block.

More: Code and includes.

Notes — a box that sets text apart, one of the admonitions

Note

.. note::

   This box is rendered from the source shown above.

Note

This box is rendered from the source shown above.

```{note}
This box is rendered from the source shown above.
```

The MyST form renders live in the MyST note.

More: Admonitions.

Figures — an image with a caption

Figure

.. figure:: /_static/ubCode_icon_light.svg
   :alt: The ubCode mark
   :width: 96px

   The ubCode mark.
The ubCode mark

The ubCode mark.

```{figure} /_static/ubCode_icon_light.svg
:alt: The ubCode mark
:width: 96px

The ubCode mark.
```

The MyST form renders live in the MyST figure.

More: Figures.

Tables — rows written as a two-level list

List table

.. list-table::
   :header-rows: 1

   * - Builder
     - Writes
   * - ``ubc build html``
     - A static site.
   * - ``ubc build pdf``
     - One PDF file.

Builder

Writes

ubc build html

A static site.

ubc build pdf

One PDF file.

```{list-table}
:header-rows: 1

* - Builder
  - Writes
* - `ubc build html`
  - A static site.
* - `ubc build pdf`
  - One PDF file.
```

The MyST form renders live in the MyST list table.

More: List tables.

Needs — a requirement, and a specification linked to it

Two linked needs

.. req:: Sign in with a company account
   :id: EX_HUB_RST_REQ
   :status: open

   A user signs in with the account the company directory holds.

.. spec:: Sign in through the directory
   :id: EX_HUB_RST_SPEC
   :status: open
   :links: EX_HUB_RST_REQ

   The sign-in page hands the user to the directory.
Requirement: Sign in with a company account EX_HUB_RST_REQ
status: open
links incoming: EX_HUB_RST_SPEC

A user signs in with the account the company directory holds.

Specification: Sign in through the directory EX_HUB_RST_SPEC
status: open
links outgoing: EX_HUB_RST_REQ

The sign-in page hands the user to the directory.

```{req} Sign in with a company account
:id: EX_HUB_MYST_REQ
:status: open

A user signs in with the account the company directory holds.
```

```{spec} Sign in through the directory
:id: EX_HUB_MYST_SPEC
:status: open
:links: EX_HUB_MYST_REQ

The sign-in page hands the user to the directory.
```

The MyST form renders live in the MyST linked needs.

req and spec are the need types this site declares; yours are the ones your project declares (Need types), and a link to an id no need has is reported as you type. More: Writing needs.

Need references — a link to a need, by its id

Need references

:need:`EX_HUB_RST_SPEC` refines :need:`EX_HUB_RST_REQ`.
{need}`EX_HUB_MYST_SPEC` refines {need}`EX_HUB_MYST_REQ`.

The MyST form renders live in the MyST need references.

More: Need roles.

Need tables — the needs a filter selects, one row each

Needs table

.. needtable::
   :filter: id.startswith("EX_HUB_RST_")
   :columns: id, title, status, links
   :style: table

ID

Title

Status

Links

EX_HUB_RST_REQ

Sign in with a company account

open

EX_HUB_RST_SPEC

Sign in through the directory

open

```{needtable}
:filter: id.startswith("EX_HUB_MYST_")
:columns: id, title, status, links
:style: table
```

The MyST form renders live in the MyST needs table.

It selects the two needs above by the start of their ids; in your own project you would more often select by type or status, with :types: req or :status: open. More: Need views.

reStructuredText and MyST

A construct is shown in both markups, as two tabs. The reStructuredText tab is a live specimen: the source, and under it what this site’s own build renders from that very source. The MyST tab gives the same construct as you would write it in a Markdown file, and points to its live twin on a Markdown page. Choosing a tab chooses it on every page that offers the same two.

Basics

The plain markup every page is made of, and the same in Markdown:

  • reStructuredText basics — inline markup, sections, lists, literal and line blocks, block quotes, transitions and comments.

  • reStructuredText tables — grid and simple tables, and the list-table, csv-table and table directives.

  • References and links — targets and :ref:, hyperlinks, footnotes, citations, substitutions, and the roles that link to documents, terms and files.

  • Roles — inline roles such as :kbd:, :pep:, badges, and your own custom roles.

  • Markdown (MyST) — writing content in Markdown rather than reStructuredText, and how it maps to the same preview.

Needs and traceability

The requirements, specifications and tests a project traces, and where they come from:

  • Needs — need directives and how they render as need cards.

  • Variants — the if directive, the variant role, and variant field values.

  • Test reports: the directives — the sphinx-test-reports directives, which create a need from a JUnit test report.

  • Traced source code — the src-trace directive, which brings needs written as comments in source code into a page.

  • Templates: generating content from data — the ub-template directive and template directives of your own, which generate needs and other content from a data file through a template.

Everything else

More constructs, and where ubCode and a Sphinx build part ways:

  • Directives — block constructs such as admonitions, images and code blocks, and which ones fall back to a placeholder.

  • Layout components — sphinx-design’s grids, cards, dropdowns, accordions, tabs, buttons, asides and steps.

  • Diagrams — Mermaid and PlantUML diagram directives.

  • Unsupported syntax — the constructs ubCode does not render, and what to write instead.

  • Differences from a Sphinx build — the full register of where the preview and a real build diverge.