Re: How to indent .. code-block:: ?

663 views
Skip to first unread message

Guenter Milde

unread,
Aug 26, 2013, 6:42:11 AM8/26/13
to sphinx...@googlegroups.com
On 2013-08-23, Patryk Małek wrote:

> [-- Type: text/plain, Encoding: quoted-printable --]

> I would like to indent the whole *.. code-block::* . Can anyone suggest me
> how can I do this ?

> The problem is that I have an unnumbered list with code snippets, I can do
> something like :

> * a) ``<simulators><xxx><sub_tag>`` : such sub tags are placed in top
> level in all *INI* files for all simulators; eg.: if you have the
> following::*
> *
> *
> * <?xml version="1.0" encoding="UTF-8"?>*
> * <simulators>*
> * …*
> * </simulators>*

> where I will get the correct indentation but then I will get an error

> *ERROR: Unexpected indentation.*

> Therefore I would like to use code-block and use xml syntax highlighting.

(If the indentation and leading "*"s are the same in your source, this is no
wonder. So let us assume this is mangled by some group/mail/news software.)

However, with

a) ``<simulators><xxx><sub_tag>``: such sub tags are placed in top level
in all *INI* files for all simulators, eg., if you have the following:

.. code:: xml

<?xml version="1.0" encoding="UTF-8"?>
<simulators>

</simulators>

there should be no problem.

* indent the directive tagline with the same amount as the preceding paragraph
(in this case the content of the ordered list).

* indent the content relative to the tagline.
The first content line's indent marks the left margin of the content
block, i.e.

.. code:: xml

<?xml version="1.0" encoding="UTF-8"?>
<simulators>

will fail.

* the `"code" directive`__ is part of Docutils while "code-block" is a Sphinx
extension. Use whatever works better in your project.

__ http://docutils.sourceforge.net/docs/ref/rst/directives.html#code


Günter


Reply all
Reply to author
Forward
0 new messages