Search code examples
pythonpython-sphinxread-the-docs

Preventing bold text in download links in Sphinx Read the Docs


During documenting a python library using Sphinx and the RTD theme I was linking some PDF files for download using the :download: Download Text <_download/the_file.pdf> role but for some reason this results in links that look like:

Download Text

The first word is normal but all following words are boldface. This is just rather annoying. Is there a way to stop the boldface on the 2nd, 3rd, etc words in the download link text?


Solution

  • Answering my own question here...

    I have overridden theme styles before and so I did the same thing here.

    I added a CSS file named theme_overrides.css to the _static folder in the Sphinx root directory with the contents:

    /* override the bold words in download links */
    @media screen and (min-width:767px) {
    
        .rst-content code.xref {
        /* !important prevents the common CSS stylesheets from overriding
             this as on RTD they are loaded after this stylesheet */
            font-weight: inherit !important;
        }
    }
    

    The only thing that worries me is that this might remove bold font in other places that use the .rst-content code.xref style. But so far I haven't found any.

    Then add the following to the conf.py file for the Sphinx setup:

    html_context = {
        'css_files': [
            '_static/theme_overrides.css',  # override bold download text in RTD theme
            ],
         }
    

    Credit to Rackspace Documentation Guides on http://rackerlabs.github.io/docs-rackspace/tools/rtd-tables.html for this solution.