休息删除线
是否可以在重组文本中删除文本?
例如,转换为 HTML 时呈现为 标记的内容,例如: 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
按照 Ville Säävuori 的建议,我更好地检查了文档,并决定添加删除线,如下所示:
在文档中,可以按如下方式应用此操作:
然后在我的
css
文件中,我有一个条目: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:至少有三种方法可以做到这一点:
应用 rst2html 后,您将得到:
你以一种风格来使用它们
这里我以
admonition
指令为例,但任何允许
:class:
选项的指令就可以了。由于它生成
span
,所以role
指令是唯一一个允许将您的样式应用到段落的一部分。
将类
strike
添加到也命名为的指令是多余的strike
,按照 Gozzilli 的建议,因为指令名称是默认的html 输出的类。
我已经使用
rest2html
和 Sphinx 检查了这些语法。但而
rest2html
的class
一切都按预期工作指令因 Sphinx 失败。您必须将其替换为
This is only
Sphinx Rest Primer 的脚注。
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 anydirective that allow the
:class:
option would do.As it generates a
span
therole
directive is the only one thatallow 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 defaultclass for the html output.
I have checked these syntax both with
rest2html
and Sphinx. Butwhile everything works as expected with
rest2html
theclass
directive fail with Sphinx. You have to replace it with
This is only stated in a small
footnote of Sphinx reSt Primer.
根据官方规范,没有删除线指令< ReST 中的 /strong> 标记。
但是,如果环境允许 :raw: 角色或者您能够编写自己的角色,那么您可以为其编写自定义插件。
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.
我发现其他答案非常有帮助。
我对 Sphinx 不是很熟悉,但我正在将它用于一个项目。我也想要删除线功能,并根据之前的答案让它发挥作用。
需要明确的是,我添加了 gozzilli 提到的删除线角色,但我使用 rst_prolog 变量将其保存在我的 conf.py 中,如堆栈溢出线程 此处。这意味着该角色可用于您的所有其余文件。
然后,我通过在源目录内的
_templates
中创建layout.html
来扩展基本 html 模板,如上所述。该文件的内容是:这基本上包括所有构建的默认 html 文档的自定义 css 文件。
最后,在我的源目录中的 _static 目录中,我包含了文件
myStyle.css
,其中包含:其他答案已经提供了。
我只是写这个答案,因为以我有限的 Sphinx 经验,要编辑哪些文件对我来说并不明显。
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.
考虑到用户可能有不同的背景,所以这里没有一种解决方案可以适合所有人。
1.仅一个文件
如果您仅在一个文件上使用它。例如,您向 PyPI 发布了一个简单的项目,并且您可能只有一个 README.rst 文件。以下可能是您想要的。
您可以将其复制并粘贴到此网站:https://livesphinx.herokuapp.com/
,然后会看到图片如下:
很简单,你可以直接在一些IDE上看到预览,例如PyCharm。
下面是为Sphinx的用户写的
2.Sphinx初学者
如果您是Sphinx的初学者。 (我的意思是也许你想使用Sphinx来创建一个文档,但Python对你来说并不熟悉)然后尝试如下:
user.define.rst
user.define.css
使用
rst_prolog
,它可以在每个第一个文件上自动添加角色,但是如果您更改内容(该文件,它包含您定义的格式),那么您必须重建 以使渲染正确。3.创建角色
您可以创建一个扩展来实现它。
完整架构:
关于规则,可以参考这个链接 rst-roles
我建议您查看
docutils.parsers.rst.roles.py
。Consider the user may have a different background, so here is no one solution that can be suitable for everyone.
1.Only one file
If you only use it only on one file. For example, you published a simple project to PyPI, and you may probably just only one README.rst file. The following may you want.
you can copy and paste it on this website: https://livesphinx.herokuapp.com/
and will see the picture as the following:
It's simple, and you can on directly see the preview on some IDE, for example, PyCharm.
bellow is writing for the users of Sphinx
2.beginner of Sphinx
If you are a beginner of Sphinx. ( I mean maybe you want to use Sphinx to create a document, but Python is not familiar for you ) then try as following:
user.define.rst
user.define.css
With the
rst_prolog
, It can auto-add the role on each rst files, but if you change the content( that file, it contains a format that you define), then you must rebuild to make the render is correct.3.Create roles
You can create an extension to achieve it.
The full architecture:
about the rules, you can reference this link rst-roles
And I vary recommended you to see the
docutils.parsers.rst.roles.py
.这是
del
角色的 Python 定义,如果您想在 Pelican 博客或 Sphinx 文档项目的多个页面中使用该角色,它比公认的答案更好:更好的是扩展HTML 编写器生成正确的
标记,如下所示:当然,您可以简单地调整它以生成
。Here's a Python definition of a
del
role, which works better than the accepted answer if you want to use the role in multiple pages of a Pelican blog or a Sphinx documentation project:Even better would be to extend the HTML writer to produce a proper
<del>
tag, like this:You can trivially adjust it to produce an
<s>
, of course.我为此编写了一个扩展。
只需
pip install sphinxnotes-strike
并使用:或
显示删除文本。
欲了解更多信息:https://sphinx-notes.github.io/strike/
I wrote an extension for this.
Just
pip install sphinxnotes-strike
and use:or
to show strike text.
For more info: https://sphinx-notes.github.io/strike/
从 Docutils 0.17 开始,如果在
inline
、literal
或中找到匹配的类值,HTML5 编写器将使用
元素:
容器Spinx用户可以考虑将角色定义添加到他们的rst_prolog。
Since Docutils 0.17, the HTML5-writer uses
<del>
if a matching class value is found ininline
,literal
, orcontainer
elements:Spinx users may consider to add the role definition to their rst_prolog.