Inline code
See how inline markup looks like in the Awesome Theme.
To mark up code in inline text, you can:
Surround the code with two backtick characters.
Use the
codeinterpreted text role.
If you want to see the styles for code blocks, see Code blocks.
Syntax highlighting in inline code
By default, Sphinx doesn’t highlight inline code. To highlight inline code with Sphinx, follow these steps:
Create a docutils configuration file
docutils.confin the same directory as the Sphinx configuration fileconf.py.Add to the docutils configuration file
docutils.conf:Note
This option makes Pygments use short class names for the highlighted code. This lets you re-use the same Pygments style sheet
pygments.cssthat Sphinx already uses for code blocks.For each language you want to highlight, create a custom interpreted text role using docutils’
roledirective.For example, add this code to the beginning of an reStructuredText file:
.. role:: python(code) :language: python :class: highlightThis lets you highlight inline Python code. Adding the
highlightclass lets you re-use the Pygments CSS styles that Sphinx already uses for code blocks.Use the new role to highlight inline code. For example:
:python:`print("Hello World")`This renders
print("Hello World").
More interpreted text roles
Docutils and Sphinx have many interpreted text roles. They can be useful to convey precise semantic intentions in the reStructuredText source files. On the other hand, it might be better to only use a few different roles:
The difference between the many roles are lost in the rendered output. Most of these roles are rendered like code (or bold).
Using too many directives puts a burden on documentation writers, who have to agree and remember when to use which role.
The Awesome Theme provides styles for the following interpreted text roles.
Files and directories
You can designate files with the file role.
:file:`Some file name`
This renders as Some filename.
You can highlight placeholder text in file and directory names using the following syntax:
:file:`/home/{USERNAME}/`
This renders as /home/USERNAME/.
Tip
To distinguish directories from files, you can append a Slash (/) character to directory names.
Inline code with placeholder text
To highlight inline code with placeholder text,
use the samp interpreted text role:
:samp:`Replace {PLACEHOLDER}`
This renders as Replace PLACEHOLDER.
Keyboard input
Highlight keyboard shortcuts with the kbd interpreted text role:
:kbd:`Ctrl+F`
This renders as Ctrl+F.
User interface elements
Use the guilabel role to highlight user interface elements, such as buttons:
:guilabel:`Help`
This renders as Help.
Use the menuselection role to document items in menus.
:menuselection:`Start --> Program`
This renders as .