Is it possible to strike text through in Restructured Text?
Something that for example renders as a <strike>
tag when converted to HTML, like:
ReSTructuredText
Is it possible to strike text through in Restructured Text?
Something that for example renders as a <strike>
tag when converted to HTML, like:
ReSTructuredText
According to the official spec there is no directive for strikethrough markup in ReST.
However, if the environment allows for :raw: role or you are able to write your own roles, then you can write a custom plugin for it.
There is at least three ways of doing it:
After applying
rst2html
you get:You use them with a style
Here I have taken the
admonition
directive as example but any directive that allow the:class:
option would do.As it generates a
span
therole
directive is the only one that allow to apply your style to a part of a paragraph.It is redundant to add a class
strike
to a directive also namedstrike
, as suggest Gozzilli, because the directive name is the default class for the html output.I have checked these syntax both with
rest2html
and Sphinx. But while everything works as expected withrest2html
theclass
directive fail with Sphinx. You have to replace it withThis is only stated in a small footnote of Sphinx reSt Primer.
I checked the docs better, as suggested by Ville Säävuori, and I decided to add the strikethrough like this:
In the document, this can be applied as follows:
Then in my
css
file I have an entry:I found the other answers very helpful. I am not very familiar with Sphinx but I am using it for a project. I too wanted the strike-through ability and have got it working based on the previous answers. To be clear, I added my strikethrough role as gozzilli mentioned but I saved it inside my conf.py using the rst_prolog variable as discussed in the stack overflow thread here. This means that this role is available to all of your rest files.
I then extended the base html template as described above by creating
layout.html
within_templates
inside my source directory. The contents of this file are:This basically includes a custom css file to all your built default html docs.
Finally, in my _static directory within my source directory I included the file
myStyle.css
which contains:Which the other answers have already provided.
I am merely writing this answer as it wasn't obvious to me with my limited Sphinx experience which files to edit.