Page tree
Skip to end of metadata
Go to start of metadata

我们这里的Sphinx特指Sphinx doc这个项目(另一个也叫Sphinx的search的项目,虽然都叫一个名字)。

基本用法

安装

pip install sphinx

新建一个默认的文档项目

sphinx-quickstart

生成 html

make html

主题样式

默认主题为 alabaster,可以修改为 sphinx_rtd_theme,修改 conf.py

html_theme = 'sphinx_rtd_theme'

更多主题可在官网文档查看,同时也可修改主题的默认样式。

文件结构

.. toctree::
   :maxdepth: 2

   intro
   test

代码高亮

test::

   def some_function():
       interesting = False
       print 'This line is highlighted.'
       print 'This one is not...'
       print '...but this one is.'

.. code-block:: python
   :caption: this.py
   :name: this-py

   print 'Explicit is better than implicit.'

autodoc

If extensions (or modules to document with autodoc) are in another directory,
add these directories to sys.path here. If the directory is relative to the
documentation root, use os.path.abspath to make it absolute, like shown here.

修改配置文件 conf.py

sys.path.insert(0, os.path.abspath('.'))

autodoc 示例:

.. py:function:: enumerate(sequence[, start=0])

   Return an iterator that yields tuples of an index and an item of the
   *sequence*. (And so on.)

.. autofunction:: nice.say

.. automodule:: nice
   :members:




  • No labels
Write a comment...