为具有特定标题的通用斯芬克斯警告定义标记

equ*_*ghe 16 markup restructuredtext python-sphinx

我正在使用Sphinx为Python程序生成HTML文档.

我想使用具有特定标题的通用admonition指令(参见http://docutils.sourceforge.net/docs/ref/rst/directives.html#generic-admonition)并以我可以定义的方式标记它例如,像使用note指令生成的内容,即盒装,但具有不同的颜色(大多数告诫不是特别设计的,参见http://sphinx.pocoo.org/rest.html?highlight=admonition).

我最好怎么做?

Bud*_*ger 14

如果我正确理解了您的问题,您希望将一种CSS风格应用于警告.您可以使用:class:attibute执行此操作.

例如,以下内容

.. admonition:: my title goes here
   :class: myOwnStyle

   this is the admonition text
Run Code Online (Sandbox Code Playgroud)

呈现为

<div class="myownstyle admonition">
  <p class="first admonition-title">my title goes here</p>
  <p class="last">this is the admonition text</p>
</div>
Run Code Online (Sandbox Code Playgroud)

然后添加自己的样式表.例如,通过目录中_ templates目录中的自定义layout.html:

{% extends "!layout.html" %}
{% set css_files = css_files + ["_static/customstyle.css"] %}
Run Code Online (Sandbox Code Playgroud)

然后,您可以使用myownstyle类的选择器在样式表中使用CSS样式


Gri*_*ave 6

要更轻松地添加 css 文件,请将它们放在_static文件夹中,然后将其添加到conf.py

def setup(app):
    app.add_stylesheet('custom.css')
Run Code Online (Sandbox Code Playgroud)