LoginSignup
17
14

More than 5 years have passed since last update.

sphinx覚書

Last updated at Posted at 2013-07-27

themeの追加 (twitter-bootstrap)

$ sudo pip install sphinx_bootstrap_theme
conf.py
import sphinx_bootstrap_theme
html_theme = 'bootstrap'
html_theme_path = sphinx_bootstrap_theme.get_html_theme_path()
html_theme_options = {"bootswatch_theme": "united"}
$ make html

themeの修正

  1. 読み込んでいるcssの一つがbasic.cssとする。
  2. 現在使われている basic.css_static/basic.css にコピー
  3. 修正して make html すると反映されていることを確認できる。

独自タグの使用

出力したhtmlをphpなどで文字列の置換を行う。

  • %%TAG_START%%文章%%TAG_END%% というように任意のタグでくくったものを出力させ、別言語で文字列置換したものを生成する。

例:

$html = preg_relace('%%TAG_START%%','<font color="red">',$html);
$html = preg_relace('%%TAG_EMD%%','</font>',$html);
  • {%だと、<span>{<span>% に展開される場合があったので見づらいけど%%が無難。

インストール

mac
easy_install sphinx
vine_linux
apt-get install python-sphinx

書式

====
見出し
====

h1
====

h2
----

h3
++++

|   改行した時、<br>扱い。code-blockを頻繁に使う場合、 | を行頭に持ってきたほうがrstファイル上で判別しやすい。

.. code-block:: bash

    ping 8.8.8.8

  • h2は表示されないので使わない方がいい。
  • 見出し は目次に使われるが、コンテンツには出力されない。

便利と思った機能

  • 自動見出し作成
  • rstファイル上でcode-block 〜 次のcode-block までのコマンドの区切りがわかりやすい。
  • pandocで markdown を html出力させて使うよりも、テンプレートの用意が楽。

sphinxで出力したepubの文字化け対応

conf.py に epub_language = 'ja' を追加すればよい。

17
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
14