Python-sphinx: how to show linux command line snippets

Using sphinx, I know that you can show a snippet of code snippet on python or a snippet of ruby ​​code, having something like:

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

How can I show a snippet of code from Linux commands or just some console commands that are not related to any languages? I don't care if they are not properly highlighted by the syntax, I just want them to appear in the document as part of the code other than plain text. eg.

 ls -lsa . make file 
+6
source share
3 answers

You can backtrack from the text you want to write as code and precede the double colon. For instance:

 Some body text explaining what coming up:: ls -lsa . make file 

Or it also turns out that you can leave without text earlier by simply using double colons. In the first case, one colon is processed, and for this case, the code simply receives the visualization.

 :: mkdir test cd !$ 

Then the commands will come out in a font with a fixed width and, depending on the style sheets you have selected, are also highlighted (highlighted in green by default).

You can also turn on backlighting, for example. `ls -lsa .` .

+7
source

For Linux console commands, you can use bash or sh :

 .. code-block:: bash $ ls -lsa . $ make file 

The backlight probably won't work correctly all the time, but at least you give it a shot.

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

 .. highlight:: sh 
+12
source
 .. code-block:: console 

Designed for interactive sessions. Bash or sh does not work for me.

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

+10
source

Source: https://habr.com/ru/post/944361/


All Articles