Search code examples
python-sphinxrestructuredtext

Including a literal block inside an admonition


I'm an RST newbie. I want to create a Warning block that includes a line of code.

Here are four attempts:

.. WARNING:: Base case - This doesn't format the next line as a literal::
   $ ls /

.. WARNING:: Split over two lines - This still doesn't format the next line
   as a literal::
   $ ls /

.. WARNING:: Indented - Still no luck::
     $ ls /

.. WARNING:: Split line AND indented. Works, but gives a warning "Unexpected
   indentation"::
     $ ls /

And here is the result from Sphinx.

Output from Sphinx

The last example gives the output I am looking for, but I get a warning from Sphinx when it runs it.

What am I missing?


Solution

  • I worked it out. Shortly after posting, I randomly hit on an answer through hitting arbitrary buttons until it worked:

    .. WARNING:: The magic incantation - a blank line::
    
       $ ls /