Removing the view source link when using Read The Docs & Sphinx with ReadTheDocs Theme
Asked Answered
F

3

17

Is there any way to remove the "View page source" link from a sphinx generated read the docs theme page?

enter image description here

There is a similar question here and it recommends finding the breadcrumbs file, but I can't find one

Forbid answered 17/1, 2018 at 7:59 Comment(0)
A
29

In your conf.py file, try setting the variable html_show_sourcelink to False,

html_show_sourcelink = False

If it does not exist, just create it. Then, compile again the project,

$ make html
Apprehension answered 11/3, 2018 at 8:8 Comment(0)
A
7

Don't be fooled by the configuration. You can see the source code.

In fact, from the HTML theming support of Sphinx, it introduced that the structure of a theme should look like this.

[theme]
inherit = base theme
stylesheet = main CSS name
pygments_style = stylename
sidebars = localtoc.html, relations.html, sourcelink.html, searchbox.html
...

here is site-packages/sphinx_rtd_theme/theme.conf

[theme]
inherit = basic
stylesheet = css/theme.css
pygments_style = default

So we know that its sidebars completely inherited from basic.

What is basic? One of the themes of the sphinx.

site-packages/sphinx/theme/ {basic, nature...}

The contents of site-packages/sphinx/themes/basic/sourcelink.html

...
{%- if show_source and has_source and sourcename %}
  <div role="note" aria-label="source link">
    <h3>{{ _('This Page') }}</h3>
    <ul class="this-page-menu">
      <li><a href="{{ pathto('_sources/' + sourcename, true)|e }}"
            rel="nofollow">{{ _('Show Source') }}</a></li>
    </ul>
   </div>
{%- endif %}

(If you are confused with this format, please reference here: jinja))

And then, we know that show if and only if the show_source, has_source, sourcename all the True.

What is show_source, has_source, sourcename ?

If your format is HTML, then it's coming from: sphinx.builders.html StandaloneHTMLBuilder

Among them, he created a variable globalcontext, see below:

class StandaloneHTMLBuilder(Builder):
    ...

    def prepare_writing(...):
        ...
        self.globalcontext = {
            'has_source': self.config.html_copy_source,
            'show_source': self.config.html_show_sourcelink,
        }
        ...
        
    ...
    
    def get_doc_context(...):
        ...
        # the name for the copied source
        if self.config.html_copy_source:
            sourcename = docname + source_suffix
            if source_suffix != self.config.html_sourcelink_suffix:
                sourcename += self.config.html_sourcelink_suffix
        else:
            sourcename = ''


Click the link if you want to see the full code


Now, I think you already get it.

has_source is html_copy_source

show_source is html_show_sourcelink

and sourcename = ... if html_copy_source else ''

So, the close way has two, both ok.

  1. html_copy_source = False (since has_source + html_copy_source)
  2. html_show_sourcelink = False (since show_source + htm_show_sourcelink )

(or 3. both eq False ...)

Ashworth answered 28/5, 2020 at 9:34 Comment(1)
Lord, is that you?Minima
A
4

It doesn't work in my side with @lucasrodesg's answer, my Sphinx vertion is 1.8.2, I just removed 'sphinx.ext.viewcode' of extensions variable in the conf.py and worked. Just like in the following code, uncomment the last line.

extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
'sphinx.ext.coverage',
'sphinx.ext.mathjax',
# 'sphinx.ext.viewcode',]
Alaniz answered 10/12, 2018 at 12:15 Comment(1)
Same here. Turning off html_show_sourcelink did not work for me, but this did. Thank you!!Parricide

© 2022 - 2024 — McMap. All rights reserved.