10

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

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

4

4 回答 4

15

我想要的只是在我的 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.`
于 2014-07-24T11:15:19.080 回答
9

为了自定义现有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 文件?.

于 2015-05-19T19:41:47.597 回答
4

除非我误解了您,否则标准 Sphinx 文档会告诉您如何修改现有主题和创建新主题。

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

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

于 2013-01-31T13:25:40.103 回答
1

对于 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;
}
于 2018-11-21T16:11:09.303 回答