Sphinx の collapsiblesidebar

何ヶ月か前に偶然使ってるサイトを見かけて、どうやってるのかと思ってたのよね。

これ:
sphinx_collapsiblesidebar

WP Pygments Syntax Highlighter、というよりはpygmentize.cgiでは、template を書き換えるやり方で出来ました。その気はなかったんだけど、偶然気付いたのよね:

theme.conf
 1 [theme]
 2 inherit = default
 3 stylesheet = pygmentize_cgi_doc.css
 4 pygments_style = sphinx
 5 
 6 [options]
 7 rightsidebar = false
 8 stickysidebar = false
 9 collapsiblesidebar = true
10 externalrefs = false
11 
12 footerbgcolor    = #11303d
13 footertextcolor  = #ffffff
14 sidebarbgcolor   = #1c4e63
15 sidebarbtncolor  = #3c6e83
16 sidebartextcolor = #ffffff
17 sidebarlinkcolor = #98dbcc
18 relbarbgcolor    = #133f52
19 relbartextcolor  = #ffffff
20 relbarlinkcolor  = #ffffff
21 bgcolor          = #ffffff
22 textcolor        = #000000
23 headbgcolor      = #f2f2f2
24 headtextcolor    = #20435c
25 headlinkcolor    = #c60f0f
26 linkcolor        = #355f7c
27 visitedlinkcolor = #355f7c
28 codebgcolor      = #eeffcc
29 codetextcolor    = #333333
30 
31 bodyfont = sans-serif
32 headfont = 'Trebuchet MS', sans-serif

これってどこから持ってくるかというと、Sphinx パッケージ内、例えば c:/Python27/Lib/site-packages/sphinx-1.2.3-py2.7.egg/sphinx/themes/default とかね。ここらへんからコピーしてきてカスタマイズするわけです。

このためには、自分のテンプレートがどこにあるかとテンプレートの名前を Sphinx に conf.py で教えてあげる必要がある:

conf.py
 1 # -- Options for HTML output ----------------------------------------------
 2 
 3 # The theme to use for HTML and HTML Help pages.  See the documentation for
 4 # a list of builtin themes.
 5 html_theme = 'pygmentize_cgi_doc'
 6 
 7 # Theme options are theme-specific and customize the look and feel of a theme
 8 # further.  For a list of options available for each theme, see the
 9 # documentation.
10 #html_theme_options = {}
11 
12 # Add any paths that contain custom themes here, relative to this directory.
13 html_theme_path = ['_templates']

実物はhttps://bitbucket.org/hhsprings/pygmentize_cgi/src/にあるので、参考にどうぞ。

そうなんだけど、collapsiblesidebar が目的でカスタマイズしたわけではないのね。文字を大きくしたりとか、ヘディングの見栄えを変えたりとかが本題だったの。なので、「自作テンプレート」しなくてもきっと collapsiblesidebar 出来るに違いない、と思ってさ。

こういうことか:

conf.py
 1 # -- Options for HTML output ----------------------------------------------
 2 
 3 # The theme to use for HTML and HTML Help pages.  See the documentation for
 4 # a list of builtin themes.
 5 html_theme = 'default'  # これは自作ではなくて
 6 
 7 # Theme options are theme-specific and customize the look and feel of a theme
 8 # further.  For a list of options available for each theme, see the
 9 # documentation.
10 html_theme_options = {'collapsiblesidebar': True}
11 
12 # Add any paths that contain custom themes here, relative to this directory.
13 html_theme_path = ['_templates']