Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I highlight text in python-sphinx?

I'm looking for a way to highlight text in python sphinx. I have seen documentation on how to change the font colour of individual words, but I want to change the background colour of individual words.

like image 807
user375 Avatar asked Apr 01 '26 22:04

user375


1 Answers

Sphinx already supports highlighted text with the s5defs.txt standard definition file intended for inclusion (but is missing the CSS file):

  1. Create/append this text to the value of rst_epilog sphinx configuration, in your docs/conf.py file:

    rst_epilog = """
    .. include:: <s5defs.txt>
    """
    
  2. Follow Sphinx's instructions to add a CSS with the outline you like:

    • Place your css file into e.g. _static/css/s4defs-roles.css;
    • append it's path into shtml_css_files sphinx configuration:

      html_css_files = [
          'css/s4defs-roles.css',
      ]
      

You may then use:

Some :outline:`outlined text` at last!

TIP: Read this SO if you also want the styling to appear in Latex output.

like image 55
ankostis Avatar answered Apr 08 '26 05:04

ankostis



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!