Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sphinx RTD theme: Change color of inline code

I use Sphinx with the Read the Docs theme. For small inline code snippets, such as the mention of a single variable among a piece of text, I use double backticks to format the code as what's called "inline literals" in the documentation.

  1. Is this the proper way to format inline code snippets?

Unlike proper code blocks, no language specific syntax highlighting is performed on the inline code snippets (that's fine). As seen in the linked documentation above (see the below screen shot), all such "inline literals" are colored red.

enter image description here

  1. How can I change this color to something else?

I'm only concerned with the HTML output of Sphinx.

like image 785
jmd_dk Avatar asked Nov 16 '25 20:11

jmd_dk


1 Answers

I found a solution, though it involves changing the Sphinx RTD theme source code.

The HTML coloring used by the RTD theme is specified in sphinx_rtd_theme/static/css/theme.css, with the sphinx_rtd_theme directory located in the site-packages directory of the Python installation. The red color used is #e74c3c and the specific place which sets this color for inline literals is

literal{color:#e74c3c}

Changing this color does exactly what I want. Making changes directly to theme_css feels wrong though. The specific change takes place on line 4, which is over 100000 characters wide! Clearly this file is generated from other files. I guess the proper solution involves performing the change do one of these (to me unknown) files.

Edit: Proper solution

With a custom .css file, the colors of the inline literals can be set using

code.literal {
    color: #404040 !important;
    background-color: #fbfbfb !important;
}

The name of a .css file containing the above should be added to html_css_files in the Sphinx conf.py, i.e.

# conf.py
html_css_files = ['custom.css']
like image 136
jmd_dk Avatar answered Nov 18 '25 10:11

jmd_dk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!