有没有一种简单的方法来自定义现有的sphinxdoc
主题?对于默认主题,有很多主题属性,但在 sphinxdoc 中我什至无法设置徽标或更改某些颜色。
或者你能推荐一个我可以学习如何修改主题的网站吗?
有没有一种简单的方法来自定义现有的sphinxdoc
主题?对于默认主题,有很多主题属性,但在 sphinxdoc 中我什至无法设置徽标或更改某些颜色。
或者你能推荐一个我可以学习如何修改主题的网站吗?
我想要的只是在我的 sphinx 文档中添加ReST 删除线。这是我的做法:
$ cd my-sphinx-dir
$ mkdir -p theme/static
$ touch theme/theme.conf
$ touch theme/static/style.css
在theme/theme.conf
:
[theme]
inherit = default
stylesheet = style.css
pygments_style = pygments.css
(这使它看起来像默认主题(l.2))
在theme/static/style.css
:
@import url("default.css"); /* make sure to sync this with the base theme's css filename */
.strike {
text-decoration: line-through;
}
然后,在你的 conf.py 中:
html_theme = 'theme' # use the theme in subdir 'theme'
html_theme_path = ['.'] # make sphinx search for themes in current dir
更多信息:https ://sphinx.readthedocs.io/en/master/theming.html 。
(可选)在 global.rst 中:
.. role:: strike
:class: strike
在 example.rst 中:
.. include:: global.rst
:strike:`This looks like it is outdated.`
为了自定义现有sphinxdoc
主题,您需要创建包含所需修改的自定义模板和样式表。
_template
和_static
子文件夹在您的 sphinx 文档文件夹(docs
在此示例中命名)中,创建两个子文件夹:_static
和_templates
:
docs
├── conf.py
├── index.rst
└── _templates
└── page.html
└── _static
└── style.css
style.css
样式表在该_static
文件夹中,创建一个style.css
包含您希望覆盖的 CSS 选项的文件。sphinxdoc
您可以通过查看sphinx 安装文件夹中的主题样式表来找到适用的选项:
./python3.4/site-packages/Sphinx-1.3.1-py3.4.egg/sphinx/themes/sphinxdoc/static/sphinxdoc.css_t`
要将文档背景从白色更改为黑色,请将以下行添加到style.css
:
body {
background-color: black;
color: white;
}
div.document {
background-color: black;
}
要使用该.. rst-class:: centered
指令添加使代码居中的功能,请添加以下行:
.centered {
text-align: center;
}
ETC...
page.html
模板在_templates
子文件夹中,创建一个page.html
包含以下内容的文件:
{% extends "!page.html" %}
{% set css_files = css_files + ["_static/style.css"] %}
这告诉 sphinx在文件夹中查找style.css
样式表。_static
这些说明来自关于主题的 Tinkerer 文档:http: //tinkerer.me/doc/theming.html。Tinkerer 是一个基于 Sphinx 的博客引擎。
另请参阅:如何添加自定义 css 文件?.
除非我误解了您,否则标准 Sphinx 文档会告诉您如何修改现有主题和创建新主题。
我实际上安装了 Sphinx云主题,然后开始编辑它的模板;所以我有了一个新主题,我可以准确地看到需要什么,但我不需要从头开始创建。
如果要更改 CSS 布局,可以将 CSS 文件(或图像)添加到_static
您的子目录中source
,并根据需要编辑您conf.py
的。同样,云主题是我最好的例子。
对于 Sphinx 1.8.2,默认主题是Alabaster,我通过添加一个配置了html_style的新样式表来自定义它:
conf.py
:
html_style = 'custom.css'
_static/custom.css
:
@import url("alabaster.css");
blockquote{
background: white;
color: black;
display: block;
}