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):
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):
How can I achieve colored text without undesired spaces in front of the colored piece?
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.