Chr*_*ian 7 python themes python-sphinx
有一种简单的方法来定制现有sphinxdoc主题吗?对于默认主题,有许多主题属性,但在sphinxdoc中,我甚至无法设置徽标或更改某些颜色?
或者你能推荐一个我可以学习如何修改主题的网站吗?
Rol*_*olf 12
我想要的只是在我的sphinx doc中添加ReST删除线.我是这样做的:
$ cd my-sphinx-dir
$ mkdir -p theme/static
$ touch theme/theme.conf
$ touch theme/static/style.css
Run Code Online (Sandbox Code Playgroud)
在theme/theme.conf:
[theme]
inherit = default
stylesheet = style.css
pygments_style = pygments.css
Run Code Online (Sandbox Code Playgroud)
(这使它看起来像默认主题(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;
}
Run Code Online (Sandbox Code Playgroud)
然后,在你的conf.py中:
html_theme = 'theme' # use the theme in subdir 'theme'
html_theme_path = ['.'] # make sphinx search for themes in current dir
Run Code Online (Sandbox Code Playgroud)
更多信息:https://sphinx.readthedocs.io/en/master/theming.html.
(可选)在global.rst中:
.. role:: strike
:class: strike
Run Code Online (Sandbox Code Playgroud)
在一个例子中:
.. include:: global.rst
:strike:`This looks like it is outdated.`
Run Code Online (Sandbox Code Playgroud)
要自定义现有sphinxdoc主题,您需要创建包含所需修改的自定义模板和样式表.
_template和_static子文件夹在您的sphinx文档文件夹(docs在此示例中命名)中,创建两个子文件夹:_static和_templates:
docs
??? conf.py
??? index.rst
??? _templates
??? page.html
??? _static
??? style.css
Run Code Online (Sandbox Code Playgroud)
style.css 样式表在该_static文件夹中,创建一个style.css包含要覆盖的CSS选项的文件.您可以通过查看sphinxdocsphinx安装文件夹中的主题样式表找到适用的选项:
./python3.4/site-packages/Sphinx-1.3.1-py3.4.egg/sphinx/themes/sphinxdoc/static/sphinxdoc.css_t`
Run Code Online (Sandbox Code Playgroud)
要将文档背景从白色更改为黑色,请将以下行添加到style.css:
body {
background-color: black;
color: white;
}
div.document {
background-color: black;
}
Run Code Online (Sandbox Code Playgroud)
要添加使用.. rst-class:: centered指令集中代码的功能,请添加以下行:
.centered {
text-align: center;
}
Run Code Online (Sandbox Code Playgroud)
等等...
page.html 模板在_templates子文件夹中,创建一个page.html包含以下内容的文件:
{% extends "!page.html" %}
{% set css_files = css_files + ["_static/style.css"] %}
Run Code Online (Sandbox Code Playgroud)
这告诉sphinx style.css在_static文件夹中查找样式表.
这些说明来自Tinkerer关于主题的文档:http://tinkerer.me/doc/theming.html.Tinkerer是一个基于Sphinx的博客引擎.
另请参阅:如何添加自定义css文件?.
| 归档时间: |
|
| 查看次数: |
10419 次 |
| 最近记录: |