Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

define mark up for generic sphinx admonitions with a specific title

Tags:

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/directives.html#generic-admonition) with a specific title and have it marked up in a way I can define, for example like content generated with the note directive, i.e., boxed, but with a different color (most admonitions are not specially styled, cf. http://sphinx.pocoo.org/rest.html?highlight=admonition).

How do I best go about this?

like image 705
equaeghe Avatar asked Feb 06 '12 15:02

equaeghe


People also ask

How do you use a sphinx code block?

Literal code blocks (ref) are introduced by ending a paragraph with the special marker :: . The literal block must be indented (and, like all paragraphs, separated from the surrounding ones by blank lines): This is a normal text paragraph.

What is RST Sphinx?

RST stands for ReStructured Text. It is the standard markup language used for documenting python packages. Sphinx is the Python package that generates an html website from RST files, and it is what we are using to generate this site.


2 Answers

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: myOwnStyle

   this is the admonition text

renders as

<div class="myownstyle admonition">
  <p class="first admonition-title">my title goes here</p>
  <p class="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

like image 190
Bud P. Bruegger Avatar answered Sep 21 '22 05:09

Bud P. Bruegger


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

def setup(app):
    app.add_stylesheet('custom.css')
like image 32
Gringo Suave Avatar answered Sep 21 '22 05:09

Gringo Suave