使用sphinx生成美觀的文檔

jopen 8年前發布 | 33K 次閱讀 程序文檔工具

先上效果圖


詳情

首先,需要知道什么是restructuredtext,可以理解為類似于markdown的一個東西。

然后

  1. 安裝,pip install sphinx
  2. 進入存放文檔的目錄,在命令行,sphinx-quickstart,根據需要一路回車,會生成一堆東西,包括conf.py和make等
  3. 根據需要修改conf.py
  4. 編寫rst文件,比如默認的index.rst或鏈接的rst文件。
  5. 在命令行,make html

上圖的效果,是使用了一個主題叫sphinx_bootstrap_theme。(PS.有很多主題可以選擇)

conf.py中關于這個主題的配置是加了下面幾行代碼

import sphinx_bootstrap_theme
html_theme = 'bootstrap'
html_theme_path = sphinx_bootstrap_theme.get_html_theme_path()
html_theme_options = {
    'navbar_title': "Sandglass",
    'globaltoc_depth': 2,
    'globaltoc_includehidden': "true",
    'navbar_class': "navbar navbar-inverse",
    'navbar_fixed_top': "true",
    'bootswatch_theme': "united",
    'bootstrap_version': "3",
}


生成的文檔的文件夾布局



圖中的index.rst文件

Welcome to sandglass's documentation!
=====================================

安裝
------------

  pip install sandglass


概覽
--------

**sandglass(沙漏)** 是一個增強的、友好的時間處理庫,目的是為了解放程序員的生產力。
在python中有太多處理時間的庫,datetime/date/time/calendar等等。需要記的細節太多,選擇困難。
而sandglass就是解決這個的青霉素。從各種麻煩的轉換中解脫出來。
只需記住 **Sandglass對象** 和 **ben()** 、 **tslice()** 、 **cronwalk()** 這幾個主要的api即可。

特性
----------
 + api簡潔,開箱即用
 + 增強接管datetime
 + (此次略去xx字)

快速上手
---------
在sandglass中,核心對象是 **Sandglass對象** 。通過這個對象,可以方便的獲取各個時間屬性和操作::

    #獲取屬性
    >>>sg = ben('2013,1,1 13:14:15')
    >>>sg.year,sg.month,sg.day,sg.hour,sg.minute,sg.second,sg.microsecond
    (2013, 1, 1, 13, 14, 15, 0)
    (此次略去xx字)

API文檔
-----------------

.. toctree::
   :maxdepth: 2

   api

Todo
---------
* Add timezone support

Changelog
---------
**0.0.1**

* Initial release

Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`


更多詳情請看sphinx的官方文檔

以及sphinx-bootstrap-theme主題的官方文檔



來自: http://blog.csdn.net/handsomekang/article/details/46778895

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!