Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 自定义sphinxdoc主题_Python_Themes_Python Sphinx - Fatal编程技术网

Python 自定义sphinxdoc主题

Python 自定义sphinxdoc主题,python,themes,python-sphinx,Python,Themes,Python Sphinx,有没有一种简单的方法可以自定义现有的sphinxdoc主题?对于默认主题,有许多主题属性,但在sphinxdoc中,我甚至无法设置徽标或更改某些颜色 或者你能给我推荐一个可以学习如何修改主题的网站吗?除非我误解了你,否则网站会告诉你如何修改现有主题和创建新主题 我实际上安装了斯芬克斯,然后开始编辑它的模板;所以我有了一个新的主题,在那里我可以准确地看到需要什么,但我不需要从头开始创建 如果要更改CSS布局,可以将CSS文件(或图像)添加到源代码的静态子目录中,并根据需要编辑conf.py。同样,

有没有一种简单的方法可以自定义现有的
sphinxdoc
主题?对于默认主题,有许多主题属性,但在sphinxdoc中,我甚至无法设置徽标或更改某些颜色


或者你能给我推荐一个可以学习如何修改主题的网站吗?

除非我误解了你,否则网站会告诉你如何修改现有主题和创建新主题

我实际上安装了斯芬克斯,然后开始编辑它的模板;所以我有了一个新的主题,在那里我可以准确地看到需要什么,但我不需要从头开始创建

如果要更改CSS布局,可以将CSS文件(或图像)添加到
源代码的
静态
子目录中,并根据需要编辑
conf.py
。同样,云主题是我最好的例子。

我只想添加到我的sphinx文档中。我是这样做的:

$ 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))

主题/static/style.css
中:

@import url("default.css"); /* make sure to sync this with the base theme's css filename */

.strike {
    text-decoration: line-through;
}
body {
    background-color: black;
    color: white;
}
div.document {
    background-color: black;
}
@import url("alabaster.css");

blockquote{
  background: white;
  color: black;
  display: block;
}
然后,在conf.py中:

html_theme = 'theme' # use the theme in subdir 'theme'
html_theme_path = ['.'] # make sphinx search for themes in current dir
更多信息请点击此处:

(可选)在global.rst中:

.. role:: strike
   :class: strike
在示例.rst中:

.. include:: global.rst

:strike:`This looks like it is outdated.`

为了自定义现有的
sphinxdoc
主题,您需要创建一个包含所需修改的自定义模板和样式表


\u模板
\u静态
子文件夹 在sphinx文档文件夹(本例中名为
docs
)中,创建两个子文件夹:
\u static
\u templates

docs
├── conf.py
├── index.rst
└── _templates
    └── page.html
└── _static
    └── style.css

style.css
样式表 在
\u static
文件夹中,创建一个包含要覆盖的css选项的文件
style.css
。通过查看sphinx安装文件夹中的主题样式表,可以找到适用的选项:

./python3.4/site-packages/Sphinx-1.3.1-py3.4.egg/sphinx/themes/sphinxdoc/static/sphinxdoc.css_t`
要将文档背景从白色更改为黑色,请将以下行添加到
style.css

@import url("default.css"); /* make sure to sync this with the base theme's css filename */

.strike {
    text-decoration: line-through;
}
body {
    background-color: black;
    color: white;
}
div.document {
    background-color: black;
}
@import url("alabaster.css");

blockquote{
  background: white;
  color: black;
  display: block;
}
使用
添加代码居中的功能。。rst class::centered
指令,添加以下行:

.centered {
    text-align: center;
}
等等


page.html
模板 在
\u templates
子文件夹中,创建一个包含以下内容的文件
page.html

{% extends "!page.html" %}

{% set css_files = css_files + ["_static/style.css"] %}
这告诉sphinx在
\u static
文件夹中查找
style.css
样式表


更多信息 这些说明来自Tinkerer主题文档:。Tinkerer是一个基于Sphinx的博客引擎


另外,请参见:.

对于Sphinx 1.8.2,默认主题是我通过添加一个配置有以下内容的新样式表来定制的:

conf.py

html_style = 'custom.css'
\u static/custom.css

@import url("default.css"); /* make sure to sync this with the base theme's css filename */

.strike {
    text-decoration: line-through;
}
body {
    background-color: black;
    color: white;
}
div.document {
    background-color: black;
}
@import url("alabaster.css");

blockquote{
  background: white;
  color: black;
  display: block;
}

我认为该文件也可以命名为_static/custom.css\t