Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inline code highlighting in reStructuredText

People also ask

How do you highlight in code blocks?

In Code::Blocks select Settings -> Editor -> Occurrences Highlighting (scroll down in the pane on the left side to find it) and then put a check mark in the three checkboxes under Highlight occurrences of selection as shown in the below screenshot. The three checkboxes to select are: Highlight occurrences.

What is inline code?

Inline code refers to any lines of code that are added in the body of a program. It can be any type of code written in any programming language. The inline code executes independently and is usually executed under some condition by the primary program.

How do you write RST code?

rst. txt is used. In the past a simplified shorthand directive was widely used: A sentence ending with two double colon :: , followed by a new line and an indented block of code.

What is RST Sphinx?

reStructuredText is the default plaintext markup language used by Sphinx. This section is a brief introduction to reStructuredText (reST) concepts and syntax, intended to provide authors with enough information to author documents productively.


Having looked into this some more I stumbled upon the document reStructuredText Interpreted Text Roles. From this document:

Interpreted text uses backquotes (`) around the text. An explicit role marker may optionally appear before or after the text, delimited with colons. For example:

This is `interpreted text` using the default role.

This is :title:`interpreted text` using an explicit role.

It seems that there is a code role, so you can simply type

:code:`a = b + c`

to render an inline code block. To get syntax highlighting you can define a custom role. For example

.. role:: bash(code)
   :language: bash

which you can then use like so:

Here is some awesome bash code :bash:`a = b + c`.

Note that the role definition must be placed before references to the role.

Note, the document I link to makes no mention of the version of docutils to which it refers. The code role is not available in docutils 0.8.1 (which is the only version I have to test against).