Skip to content Skip to sidebar Skip to footer

Define Mark Up For Generic Sphinx Admonitions With A Specific Title

I am using Sphinx to generate HTML documentation for a Python program. I would like to use the generic admonition directive (cf. http://docutils.sourceforge.net/docs/ref/rst/direct

Solution 1:

If I understood your question correctly, you'd like to apply a custon CSS style to the admonition. You can do this with a :class: attibute.

For example, the following

.. admonition:: my title goes here
   :class: myOwnStylethisis the admonition text

renders as

<divclass="myownstyle admonition"><pclass="first admonition-title">my title goes here</p><pclass="last">this is the admonition text</p></div>

You then add your own style sheet. For example, by a custom layout.html in the _templates directory in your source directory:

{% extends "!layout.html" %}
{% set css_files = css_files + ["_static/customstyle.css"] %}

Then you can play around with CSS styles in your style sheet using a selector for the myownstyle class

Solution 2:

To add css files more easily, put them in the _static folder and then add this to conf.py:

defsetup(app):
    app.add_stylesheet('custom.css')

Solution 3:

Here is an example custom.css for overwriting the color of the title and background color of the myownstyle admonition. I used the app.add_stylesheet() call in conf.py.

.rst-content.myownstyle.admonition-title {
   background: #b99976
}

.rst-content.myownstyle {
   background: #e5d3b3
}

Post a Comment for "Define Mark Up For Generic Sphinx Admonitions With A Specific Title"