3

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.

mzjn
  • 48,958
  • 13
  • 128
  • 248
user375
  • 31
  • 1
  • 2
  • What documentation? If you know how to change the font colour, it seems like it would be straigthforward to adapt that solution to also change the background colour. – mzjn Mar 10 '18 at 17:19
  • This https://stackoverflow.com/questions/3702865/sphinx-restructuredtext-set-color-for-a-single-word If you know of a way to highlight a word with a chosen colour, please let me know. I don't see how to use font styles for this. – user375 Mar 10 '18 at 21:59
  • That question has three upvoted answers. What exactly did you try? – mzjn Mar 11 '18 at 04:14
  • I have tried all three solutions. None of them do what I want to accomplish. These solutions change the colour of the font itself. I want to highlight words by changing the background colour of a single word, the same way you would highlight a word on paper with a fluorescent marker. – user375 Mar 11 '18 at 14:10
  • Please elaborate the question. Make it clear what output format this is about. **Show us** what you have tried. Provide examples. Don't just say "None of them do what I want". – mzjn Mar 11 '18 at 15:31
  • I may be wrong, but as far as I can tell, any formatting options applied to a txt or rst file should be reflected in any output format, be it HTML, PDF or ePUB. I cannot show what for obvious reasons doesn't work. Since font colour is the opposite of what I am trying to accomplish I have not provided any example other than the examples provided in the documentation I have provided a link to above. Those font colour solutions work, but are the opposite of what I wish to accomplish. – user375 Mar 11 '18 at 22:30

1 Answers1

0

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.

ankostis
  • 8,579
  • 3
  • 47
  • 61