Search code examples
python-sphinxrestructuredtext

Nested / Compounded roles: apply multiple roles to overlapping text


In my custom.css file I have,

.bold {
    font-weight: bold;
}

.red {
    color:red;
}

And in my _.rst file,

.. role:: bold

.. role:: red

But if I try to nest/compound them, only the outermost role takes effect, e.g.


:bold:`:red:`This is only bold``

This is only bold


Is there a way to combine these effects without defining a new (combined) role?


Solution

  • you can use a custom css class directive:

    .. cssclass:: boldred
    
      bold red text
    

    and update the css to format the boldred class