Removing the view source link when using Read The Docs & Sphinx with ReadTheDocs Theme
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
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/theme/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 = ''
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.
- html_copy_source = False
html_show_sourcelink = False
(or 3. both eq False ...)