Skip to content Skip to sidebar Skip to footer

Applying Css And Roles For Text Blocks Instead Of Inline Spans In Sphinx

There is a previous question that explains how to add a color span to some reStructuredText. To recap the procedure: First, you have the role. .. role:: red An example of using :r

Solution 1:

There are a number of ways to do this, but one of them is to use the class directive:

.. class:: red

    This is a paragraph.

    This is another paragraph.

Most docutils HTML writers will put that into html output as a class html attribute, which you can then style with CSS.

In Sphinx, in particular, however, you may need to use rst-class instead of class in at least some cases. See: https://www.sphinx-doc.org/en/2.0/usage/restructuredtext/basics.html

Also, many block-level elements in RestructuredText take a :class: parameter which does pretty much the same thing.

Post a Comment for "Applying Css And Roles For Text Blocks Instead Of Inline Spans In Sphinx"