Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show terminal/shell code snippets in Sphinx?

Using Sphinx, I know you can show a code snippet by having something like:

.. code-block:: ruby.
  ${your ruby code goes here} 

How can I show a code snippet of terminal or shell commands not related to any languages? I don't care if they are not highlighted properly syntax wise, I just want them show up in the doc as a piece of code other than normal text.

Example

$ ls -lsa . 
$ make file
like image 965
Shengjie Avatar asked May 06 '13 11:05

Shengjie


3 Answers

.. code-block:: console

is meant for interactive sessions. Bash or sh didn't work for me.

( from http://build-me-the-docs-please.readthedocs.org/en/latest/Using_Sphinx/ShowingCodeExamplesInSphinx.html#pygments-lexers )

like image 182
Marco Mariani Avatar answered Nov 20 '22 17:11

Marco Mariani


For Linux console commands you could use bash or sh:

.. code-block:: bash

   $ ls -lsa .
   $ make file

Highlighting wouldn't probably work right all the time, but at least you give it a chance.

You can also set the default highlighting in the beginning of the file if you use the @Bonlenfum way with double colons:

.. highlight:: sh
like image 37
wswld Avatar answered Nov 20 '22 15:11

wswld


You can indent the text you want to be written as code, and precede that with a double colon. For example:

Some body text explaining what's coming up::

    ls -lsa .
    make file

Or it also turns out you can get away without any text before, just using the double colons. In the first case, one colon gets rendered, while for this case, just the code gets rendered.

::
    mkdir test
    cd !$  

Then the commands will come out in a fixed-width font, and, depending on the style sheets you've chosen, highlighted as well (by default, highlighted with green background).

You can also inline-highlight with backticks, e.g. `ls -lsa .`.

like image 24
Bonlenfum Avatar answered Nov 20 '22 16:11

Bonlenfum