Is there any way to remove the "View page source" link from a sphinx generated read the docs theme page?
There is a similar question here and it recommends finding the breadcrumbs file, but I can't find one
Is there any way to remove the "View page source" link from a sphinx generated read the docs theme page?
There is a similar question here and it recommends finding the breadcrumbs file, but I can't find one
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/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.
html_copy_source = False
(since has_source + html_copy_source)html_show_sourcelink = False
(since show_source + htm_show_sourcelink )(or 3. both eq False ...)
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',]
html_show_sourcelink
did not work for me, but this did. Thank you!! –
Parricide © 2022 - 2024 — McMap. All rights reserved.