Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restructured Text (Sphinx) Image in Heading?

Is it possible to place an image inside of a heading using Restructured Text?

Something like:

Introduction .. image:: path/to/img.png
---------------------------------------

This renders as text, i.e. the image syntax is not parsed. I have not seen any examples of this leading me to believe it might not be possible, but perhaps someone has a work-around.

I intend to output to HTML (so a modification to the derived CSS is possible, though I would prefer to alter the RST source. This is because I also intend to output to pdf (latex).

like image 517
Jzl5325 Avatar asked Jul 16 '13 15:07

Jzl5325


People also ask

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.

What is RST documentation?

An RST file is a technical documentation file format, used primarily in the Python programming community. It is a text file written in the reStructuredText markup language that applies styles and formatting to plain text documents for generation of documentation.


1 Answers

This can be achieved by using a substitution in the header:

Header Text |foo|
=================

.. |foo| image:: path/to/img.png

Here foo is just an example substitution text. It can be anything, but should not start or end with a whitespace.

The abstract substitution syntax is as follows:

+-------+-----------------------------------------------------+
| ".. " | "|" substitution text "| " directive type "::" data |
+-------+ directive block                                     |
        |                                                     |
        +-----------------------------------------------------+

As we would like to insert an inline image, we should choose the image as the directive type.

like image 88
Nick Volynkin Avatar answered Sep 23 '22 05:09

Nick Volynkin