Bold italic in ReStructuredText
I'm writing some documentation using ReStructuredText (ReST) format for the later web-page generation using Sphinx, and I cannot find a way to write some "bold italic" text.
There are markers for the so-called 'emphasis' (italic) and 'strong emphasis' (bold) text. They are *italic text*
and **bold text**
respectively. I also read in some documentation on this format that these formatting markers cannot be simply "nested". I.e. the ***text***
(or ** *text* **
) does not produce the bold italic text.
Still there probably should be some way to produce a text emphasized both with bold and italic markers, since it is a widespread practice to mark pieces of text that way.
Although Markdown supports nesting bold and italic, reStructuredText does not (this is one of the rare cases where Markdown is more powerful, as there is no way to represent bold italics in reStructuredText).
https://gist.github.com/1855764
Recipe for HTML output.
my.rst
:
.. role:: red
:class: red
.. role:: bolditalic
:class: bolditalic
:red:`WARNING` :bolditalic:`Don't be stupid!`
my.css
:
.red { color: red; }
.bolditalic {
font-weight: bold;
font-style: italic;
}
Build by:
rst2html --strip-comments --halt warning --stylesheet=my.css my.rst my.html
In sphinx this is possible through custom roles: You make a style in css, and make a role pointing to that style. Here's an full working example of underlined text: sphinx-dev thread.
Edit:
Here's a good example: ReST strikethrough
Edit 2:
That sphinx-dev link is not available any more, so here's the gist, it very similar to the strikethrough link above:
CSS:
span.underlined {
text-decoration: underline;
}
Register role in RST:
.. role:: underlined
:class: underlined
to use it later as
:underlined:`test`
All this can be in a single RST document:
.. raw:: html
<style type="text/css">
span.underlined {
text-decoration: underline;
}
</style>
.. role:: underlined
:class: underlined
:underlined:`test`
Test it with::
rst2html5.py test01.rst test01.html