将 Read The Docs & Sphinx 与 ReadTheDocs 主题一起使用时删除视图源 link
Removing the view source link when using Read The Docs & Sphinx with ReadTheDocs Theme
有什么方法可以从阅读文档主题页面生成的 sphinx 中删除 "View page source" link 吗?
有一个类似的问题,它建议找到面包屑文件,但我找不到
在您的 conf.py
文件中,尝试将变量 html_show_sourcelink
设置为 False
、
html_show_sourcelink = False
如果不存在,就创建它。然后,重新编译工程,
$ make html
@lucasrodesg 的回答在我这边不起作用,我的 Sphinx 版本是 1.8.2,我刚刚删除了 conf.py 中的扩展变量 'sphinx.ext.viewcode' 并开始工作。就像下面的代码一样,取消最后一行的注释。
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
'sphinx.ext.coverage',
'sphinx.ext.mathjax',
# 'sphinx.ext.viewcode',]
不要被配置所迷惑。可以看源码
其实从Sphinx的HTML theming support开始就介绍了一个主题的结构应该是这样的
[theme]
inherit = base theme
stylesheet = main CSS name
pygments_style = stylename
sidebars = localtoc.html, relations.html, sourcelink.html, searchbox.html
...
这里是site-packages/sphinx_rtd_theme/theme.conf
[theme]
inherit = basic
stylesheet = css/theme.css
pygments_style = default
所以我们知道它的sidebars完全继承自basic
什么是基本?狮身人面像的主题之一。
site-packages/sphinx/theme/ {basic, nature...}
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 %}
(如果您对这种格式感到困惑,请参考这里:jinja))
然后,我们知道当且仅当show_source
、has_source
、sourcename
都为True。
什么是 show_source
、has_source
、sourcename
?
如果您的格式是 HTML,那么它来自:sphinx.builders.html StandaloneHTMLBuilder
其中,他创建了一个变量globalcontext
,见下图:
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 = ''
如果您想查看完整代码,请单击 link
现在,我想你已经明白了。
has_source 是 html_copy_source
show_source 是 html_show_sourcelink
和sourcename = ... if html_copy_source else ''
所以,关闭方式有两个,都可以。
html_copy_source = False
(因为 has_source + html_copy_source)
html_show_sourcelink = False
(因为 show_source + htm_show_sourcelink)
(或 3. 两者均为假 ...)
有什么方法可以从阅读文档主题页面生成的 sphinx 中删除 "View page source" link 吗?
有一个类似的问题
在您的 conf.py
文件中,尝试将变量 html_show_sourcelink
设置为 False
、
html_show_sourcelink = False
如果不存在,就创建它。然后,重新编译工程,
$ make html
@lucasrodesg 的回答在我这边不起作用,我的 Sphinx 版本是 1.8.2,我刚刚删除了 conf.py 中的扩展变量 'sphinx.ext.viewcode' 并开始工作。就像下面的代码一样,取消最后一行的注释。
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
'sphinx.ext.coverage',
'sphinx.ext.mathjax',
# 'sphinx.ext.viewcode',]
不要被配置所迷惑。可以看源码
其实从Sphinx的HTML theming support开始就介绍了一个主题的结构应该是这样的
[theme]
inherit = base theme
stylesheet = main CSS name
pygments_style = stylename
sidebars = localtoc.html, relations.html, sourcelink.html, searchbox.html
...
这里是site-packages/sphinx_rtd_theme/theme.conf
[theme]
inherit = basic
stylesheet = css/theme.css
pygments_style = default
所以我们知道它的sidebars完全继承自basic
什么是基本?狮身人面像的主题之一。
site-packages/sphinx/theme/ {basic, nature...}
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 %}
(如果您对这种格式感到困惑,请参考这里:jinja))
然后,我们知道当且仅当show_source
、has_source
、sourcename
都为True。
什么是 show_source
、has_source
、sourcename
?
如果您的格式是 HTML,那么它来自:sphinx.builders.html StandaloneHTMLBuilder
其中,他创建了一个变量globalcontext
,见下图:
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 = ''
如果您想查看完整代码,请单击 link
现在,我想你已经明白了。
has_source 是 html_copy_source
show_source 是 html_show_sourcelink
和sourcename = ... if html_copy_source else ''
所以,关闭方式有两个,都可以。
html_copy_source = False
(因为 has_source + html_copy_source)html_show_sourcelink = False
(因为 show_source + htm_show_sourcelink)
(或 3. 两者均为假 ...)