Skip to content
lsdocs

Writing pages #

Pages are Markdown (.md, .markdown) or reStructuredText (.rst) files under the source directory. Both produce the same document tree, so links, tables of contents and the navigation work the same way in either. See reStructuredText for what is particular to it.

Markdown #

Markdown is CommonMark with the common extensions:

  • tables, task lists (- [x] done) and strikethrough;

  • footnotes (text[^1] and [^1]: the note);

  • definition lists (a term, then : definition);

  • math: $x^2$ inline and $$x^2$$ on its own line;

  • alerts, which become admonitions:

    > [!NOTE]
    > Notes, tips, warnings and the like.
    
  • explicit heading ids: ## Install {#setup}.

Raw HTML is passed through to the HTML output.

Directives and roles #

Directives and roles from plugins, such as Sphinx's from sphinx-addons, are written as MyST writes them. A directive is a fenced block whose language is {name}: the rest of the first line is its argument, then come its options, as :name: value lines or YAML between --- lines, then its content. In reStructuredText, the same directive is written as usual:

```{versionadded} 2.0
:class: important

The *new* option.
```
.. versionadded:: 2.0
   :class: important

   The *new* option.

A role is {name} right before inline code: {kbd}`Ctrl+C`, {ref}`the setup <setup>`. A plugin says which directives and roles it handles; a {name} fence no plugin handles is kept for plugins as a custom node, and an unknown role stays text and code.

Content in tabs is a tab-set directive of tab-items, each with its label as the argument (the extras plugin). Tab sets are linked: choosing a label in one shows it in every tab set of the page that has it.

````{tab-set}
```{tab-item} Rust
Rust's way.
```
```{tab-item} Python
Python's way.
```
````
.. tab-set::

   .. tab-item:: Rust

      Rust's way.

   .. tab-item:: Python

      Python's way.

A button is a button-link directive (to a URL or a page's path) or a button-ref (to a page by its name, with or without its extension, or to a label), with its text as the content (the extras plugin, with sphinx-design's names). Without text, a button-link shows its URL and a button-ref the title of what it points to. color (primary, secondary, success, info, warning, danger, muted, light, dark, white or black) fills it, outline keeps it outlined, align (left, center or right) places it, expand makes it as wide as the page, and tooltip is shown on hover.

```{button-link} https://github.com/lsdocs
:color: primary
Get the code
```

```{button-ref} guide/setup
:align: center
```
.. button-link:: https://github.com/lsdocs
   :color: primary

   Get the code

.. button-ref:: guide/setup
   :align: center

Front matter #

A Markdown page may start with YAML between --- lines (or TOML between +++ lines). In reStructuredText, a field list at the very top of the page does the same (:title: Custom title). Keys the built-in plugins read:

KeyMeaning
titleThe page title, instead of its first heading.
nav_titleThe title in the navigation.
nav_orderSort key among the pages of a directory; pages without one come after, by file name.
nav_excludetrue leaves the page out of the navigation.
nav_childrenThe pages below this one in the navigation, in order (source paths, relative to the page or, with a leading /, to the source directory). On the root index page, it makes the navigation follow these lists instead of the directories.
sitemapfalse leaves the page out of the sitemap.

Every key is available to page templates as page.metadata. The host sets generated: true on pages a plugin generates (API pages, the index), which have no source file; the default theme gives them no edit link.

Sections and ids #

A heading starts a section, which holds everything up to the next heading of the same or a higher level. Sections get ids from their titles (## Getting started is getting-started), unless the page gives one, so page.md#getting-started links to it. Ids are unique within a page: a second ## Example is example-1.