sphinx插入css
使用role指令达到目的。
We can put following lines at the beginning of our RST file to specify its style.
.. raw:: html <style>.red {color:red}</style>
然后使用role指令:
.. role:: red
:class: red
调用role指令:
This is an :red:`inline text`.
which translates into a html rendering of
.. This is an <span class="red">inline text</span>. ..
如何分离css:
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:
{% extends "!layout.html" %}
{% set css_files = css_files + ["_static/myStyle.css"] %}
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:
.strike {
text-decoration: line-through;
}
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.
参考了:
http://stackoverflow.com/questions/6518788/rest-strikethrough
http://stackoverflow.com/questions/4669689/how-to-use-color-in-text-with-restructured-text-rst2html-py-or-how-to-insert-h
http://stackoverflow.com/questions/9698702/custom-css-styles-in-sphinx
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。