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
正如Ville Sävuori所建议的那样,我检查了这套书。
.. role:: strike
:class: strike
该文件可适用如下:
:strike:`This text is crossed out`
随后,在我的<代码>cs档案中,有以下条目:
.strike {
text-decoration: line-through;
}
至少有三种方式:
.. role:: strike
An example of :strike:`strike through text`.
.. container:: strike
Here the full block of test is striked through.
An undecorated paragraph.
.. class:: strike
This paragraph too is is striked through.
.. admonition:: cancelled
:class: strike
I strike through cancelled text.
After applying rst2html
you get:
<p>An example of <span class="strike">strike through text</span>.</p>
<div class="strike container">
Here the full block of test is striked through.</div>
<p>An undecorated paragraph.</p>
<p class="strike">This paragraph too is is striked through.</p>
<div class="strike admonition">
<p class="first admonition-title">cancelled</p>
<p class="last">I strike through cancelled text.</p>
You use them with a style
.strike {
text-decoration: line-through;
}
Here I have taken the admonition
directive as example but any
directive that allow the :class:
option would do.
As it generates a span
the role
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 named
strike
, 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 with rest2html
the class
directive fail with Sphinx. You have to replace it with
.. rst-class:: strike
This paragraph too is is striked through.
This is only stated in a small footnote of Sphinx reSt Primer.
rel=“noreferer”> 根据官方名称,在《ReST》中,没有关于通过<>/strong>的罢工指令。
然而,如果环境允许:扮演角色或你能够写出自己的角色,那么你就可以为之写出一种习俗。
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.
我随后将上文描述的基础html模板扩大,在我的来源目录中设置<代码>layout.html。 The content of this file are:
{% extends "!layout.html" %}
{% set css_files = css_files + ["_static/myStyle.css"] %}
这基本上包括给你所建的所有缺省(html)的海关档案。
最后,在我的原始目录中,I包括文件my Style.css
,其中载有:
.strike {
text-decoration: line-through;
}
其他答复已经提供。
我只是写了这一答案,因为我所看到的只有有限的Sphinx经历才可以ed。
此处为<代码>del的“灰色定义”,如果你想要在多页的Pelican blog或Sphinx文件项目中发挥作用,则该定义比公认的答案好:
from docutils import nodes
from docutils.parsers.rst import roles
def deleted_role(_role, rawtext, text, _lineno, _inliner, options={}, _content=[]):
roles.set_classes(options)
options.setdefault( classes , []).append("del")
return [nodes.inline(rawtext, text, **options)], []
roles.register_canonical_role( del , deleted_role)
更理想的是,扩大超文本撰写人编制适当的<代码><del> tag,如:
from docutils import nodes
from docutils.parsers.rst import roles
from docutils.writers._html_base import HTMLTranslator
class delnode(nodes.inline):
pass
def visit_delnode(self, node):
self.body.append(self.starttag(node, del , ))
def depart_delnode(self, node):
self.body.append( </del> )
HTMLTranslator.visit_delnode = visit_delnode
HTMLTranslator.depart_delnode = depart_delnode
def deleted_role(_role, rawtext, text, _lineno, _inliner, options={}, _content=[]):
roles.set_classes(options)
return [delnode(rawtext, text, **options)], []
roles.register_canonical_role( del , deleted_role)
当然,你可以轻而易举地加以调整,以形成<代码><s>。
使用者可能具有不同的背景,因此,这里没有一个适合每个人的解决办法。
如果你只使用一个档案。 例如,你向PyPI公布了一个简单的项目,可能只有一份README.rst文件。 阁下不妨:
.. |ss| raw:: html
<strike>
.. |se| raw:: html
</strike>
single line
=============
|ss| abc |se|defg
multiple line
=============
|ss|
line 1
line 2
|se|
789
http://livesphinx.herokuapp.com/“rel=”https://livesphinx.herokuapp.com/
and will see the picture as the following:
它很简单,而且你可以直接看到对一些国际民主和选举援助学会(例如PyCharm)的审查。
bellow is written for theuser of Sphinx
如果你是Sphinx的开端人。 (我指的是,你想利用Sphinx制作文件,但Zahur并不为你所熟悉)然后尝试如下:
# conf.py
from pathlib import Path
html_static_path = [ _static , ]
html_css_files = [ css/用户.define.cs ] # If you want to control which HTML should contain it, you can put it on the HTML, which is very like the answer by @Gregory Kuhn.
with open(Path(__file__).parent / Path( _static/css/用户.define.rst ), r ) as f:
user_define_role = f.read()
rst_prolog =
.join([ user_define_role +
,]) # will be included at the beginning of every source file that is read.
# rst_epilog =
.join([ user_define_role +
,]) # it s ok if you put it on the end.
用户.define.rst
.. role:: strike
用户.define.cs
.strike {text-decoration: line-through;}
<代码>rst_prolog, 它可以自动处理每份卷宗中的角色,但如果你改变内容(该档案包含一种你界定的格式),那么,你必须rebuild,使这一内容正确。
你们可以创造实现这一目的的延伸。
# conf.py
extensions = [ _ext.rst_roles , ]
html_static_path = [ _static , ]
html_css_files = [ css/用户.define.cs ]
# rst_roles.py
from sphinx.application import Sphinx
from docutils.parsers.rst import roles
from docutils import nodes
from docutils.parsers.rst.states import Inliner
def strike_role(role, rawtext, text, lineno, inliner: Inliner, options={}, content=[]):
your_css_strike_name = strike
return nodes.inline(rawtext, text, **dict(classes=[your_css_strike_name])), []
def setup(app: Sphinx):
roles.register_canonical_role( my-strike , strike_role) # usage: :my-strike:`content ...`
完整的结构:
关于规则,您可参考这一链接
And I vary recommended you to see the docutils.parsers.rst.roles.py
.
I wrote an extension for this.
Just pip install sphinxnotes-strike
and use:
:strike:`text`
or
:del:`text`
显示罢工案文。
For more info: https://sphinx-notes.github.io/strike/
Since Docutils 0.17, the HTML5-writer uses <del>
if a matching class value is found in inline
, literal
, or container
elements:
.. role:: del
:del:`This text has been deleted`, here is the rest of the paragraph.
.. container:: del
This paragraph has been deleted.
I ve been documenting a software package using Sphinx and reStructuredText. Within my documents, there are some long code snippets. I want to be able to have them hidden as default, with a little "...
Is there a way in rst to have automatic header numbering ? That is something like: #. Some Section =============== ... #. Some Subsection ------------------ ... #. Another Subsection -----------------...
I prefer to document each parameter (as needed) on the same line where I declare the parameter in order to apply D.R.Y. If I have code like this: def foo( flab_nickers, # a series of under ...
Instead of a blog/cms, I d like to have a static html-based site with a few (rarely updated) pages. I figure the simplest way to update them is to keep the sources in a format like ReST, and compile ...
Is Sphinx, is there way to automatically link text like #112 or r1023 to the corresponding tickets/changesets in Trac? For eg: #112 -> http://mytracsite/tickets/112 r1023 -> http://mytracsite/...
Related: How to store lightweight formatting (Textile, Markdown) in database? I want to store comment formatting in some markup language in our DB. However, we want to allow multiple formatting ...
I need a documentation system for a PHP project and I wanted it to be able to integrate external documentation (use cases, project scope etc.) with the documentation generated from code comments. It ...
I m using Django s markup package to transform restructuredText into html. Is there a way to customize the HTML writer to add a class attribute to each <p> tag? I could use the class directive ...