1

The text/code piece is the following:

Timestamps
-----------

...

1) UTC+2: 2021-06-10T09:00:42:red:`+02:00`
2) UTC: 2021-06-10T09:00:42:red:`Z`

Undesired result (no colored text achieved): enter image description here

It works when inserting a space in front of :red:, but this is not an acceptable workaround as the ISO-8601-format does not allow for spaces.

Undesired result of workaround (colored text achieved, but with spaces): colored text with spaces

How can I achieve colored text without undesired spaces in front of the colored piece?

Andreas L.
  • 3,239
  • 5
  • 26
  • 65

1 Answers1

2

As you realized, you must have a space before your role. Next you can escape the space with a backslash (\).

.. raw:: html

    <style> .red {color:red} </style>

.. role:: red

1) UTC+2: 2021-06-10T09:00:42\ :red:`+02:00`
2) UTC: 2021-06-10T09:00:42\ :red:`Z`

See a similar question and answer.

Steve Piercy
  • 13,693
  • 1
  • 44
  • 57