.. _Writing in RST - Task 5: ******************** Task 5: Code Blocks ******************** .. contents:: Table of Contents RST Code Blocks ======================== Code blocks let you display literal text with or with or without syntax highlighting. There are are several ways `to show code examples `_ or preformatted text. * The ``::`` directive is a generic code of preformatted text. Sphinx tries to guess at the language for syntax highlighted. * The ``.. code-block:: language`` directive adds syntax highlighting and args. * RST supports many languages! Here is the list: - http://pygments.org/languages/ - http://pygments.org/docs/lexers/ * Code blocks can contain `additional parameters `_, such as: - ``:linenos:`` - ``:lineno-start:`` - ``:emphasize-lines:`` - ``:caption:`` - ``:dedent:`` Here are some examples: .. code-block:: rst :caption: Generic block and syntax highlighting :: This text is in a code block. Sphinx will use generic text highlighting. .. code-block:: text :caption: Plain text block .. code-block:: text :caption: Plain text block

This text will have no styling. However, you can add parameters to the block.

.. code-block:: rst :caption: Basic code block .. code-block:: HTML