Code syntax highlighting

.. default-literal-role:: role

Sets the default literal role generated by double backticks literal syntax.

Normally, double backticks:

``abc``

is equivalent to the rST role literal role:

:literal:`abc`

This directive causes the double backticks syntax to instead generate the specified role. Invoking the directive with no argument resets the literal role back to the default of rST role literal.

Changing the literal role
Normal literal role: ``1 + 2``

.. default-literal-role:: python

Python literal role: ``1 + 2``

.. default-literal-role::

Normal literal role again: ``1 + 2``

Normal literal role: 1 + 2

Python literal role: 1 + 2

Normal literal role again: 1 + 2

.. highlight-push::

Saves the current highlight settings. The saved settings can be restored using the highlight-pop directive.

Temporarily changing the highlight language
.. highlight-push::

.. highlight:: json

The following literal block will be highlighted as JSON::

   {"a": 10, "b": null, "c": 10}

.. highlight-push::

.. highlight:: python

The following block will be highlighted as Python::

   def foo(x: int) -> None: ...

.. highlight-pop::

The following block will be highlighted as JSON::

   [1, 2, true, false]

The following literal block will be highlighted as JSON:

{"a": 10, "b": null, "c": 10}

The following block will be highlighted as Python:

def foo(x: int) -> None: ...

The following block will be highlighted as JSON:

[1, 2, true, false]
.. highlight-pop::

Restores the highlight settings saved by a prior invocation of highlight-push.


Last update: Dec 16, 2024