建议Python3.6 官方虽然说支持python2.x 但是在 Python2.x下是安装不成功的(多次尝试之后发现是不成功的)
Sphinx
将标记语言转化为html页面。
标记语言默认支持:reStructuredText,可选:markdown
read the docs
免费的文档托管服务器。
安装
首先安装Sphinx
pip install sphinx
创建文档目录(mkdir docs),根据提示输入文档的标题还有版权信息等等,指定的目录就是工作目录
? docs sphinx-quickstart
Welcome to the Sphinx 1.4.5 quickstart utility.
Please enter values for the following settings (just press Enter to
accept a default value, if one is given in brackets).
Enter the root path for documentation.
> Root path for the documentation [.]: # 配置document路径,默认当前
You have two options for placing the build directory for Sphinx output.
Either, you use a directory "_build" within the root path, or you separate
"source" and "build" directories within the root path.
> Separate source and build directories (y/n) [n]:y # 将原文件和编译文件分开
Inside the root directory, two more directories will be created; "_templates"
for custom HTML templates and "_static" for custom stylesheets and other static
files. You can enter another prefix (such as ".") to replace the underscore.
> Name prefix for templates and static dir [_]: # 配置template,static路径名称
The project name will occur in several places in the built documentation.
> Project name: crwy # 配置项目名,比如什么什么的帮助文档
> Author name(s): wuyue # 配置作者名称,比如哪个作者或者团队维护
Sphinx has the notion of a "version" and a "release" for the
software. Each version can have multiple releases. For example, for
Python the version is something like 2.5 or 3.0, while the release is
something like 2.5.1 or 3.0a1. If you don't need this dual structure,
just set both to the same value.
> Project version: 1.0.1 # 配置项目版本,比如大版本还有小版本
> Project release [1.0.1]:
If the documents are to be written in a language other than English,
you can select a language here by its language code. Sphinx will then
translate text that it generates into that language.
For a list of supported codes, see
http://sphinx-doc.org/config.html#confval-language.
> Project language [en]: zh_CN # 配置项目语言,建议写中文
The file name suffix for source files. Commonly, this is either ".txt"
or ".rst". Only files with this suffix are considered documents.
> Source file suffix [.rst]: # 配置标记语言,默认.rst
One document is special in that it is considered the top node of the
"contents tree", that is, it is the root of the hierarchical structure
of the documents. Normally, this is "index", but if your "index"
document is a custom template, you can also set this to another filename.
> Name of your master document (without suffix) [index]:
Sphinx can also add configuration for epub output:
> Do you want to use the epub builder (y/n) [n]:
Please indicate if you want to use one of the following Sphinx extensions:
> autodoc: automatically insert docstrings from modules (y/n) [n]:
> doctest: automatically test code snippets in doctest blocks (y/n) [n]:
) [n]: sphinx: link between Sphinx documentation of different projects (y/n)
: todo: write "todo" entries that can be shown or hidden on build (y/n) [n]:
> coverage: checks for documentation coverage (y/n) [n]:
> imgmath: include math, rendered as PNG or SVG images (y/n) [n]:
> mathjax: include math, rendered in the browser by MathJax (y/n) [n]:
n]: config: conditional inclusion of content based on config values (y/n) [n
y/n) [n]: : include links to the source code of documented Python objects (y
s (y/n) [n]: : create .nojekyll file to publish the document on GitHub pages
A Makefile and a Windows command file can be generated for you so that you
only have to run e.g. `make html' instead of invoking sphinx-build
directly.
> Create Makefile? (y/n) [y]: # 生成Makefile
> Create Windows command file? (y/n) [y]: # 生成windows make脚本
Creating file ./source/conf.py. #文档的编辑目录
Creating file ./source/index.rst.
Creating file ./Makefile.
Creating file ./make.bat.
Finished: An initial directory structure has been created.
You should now populate your master file ./source/index.rst. and create other documentation
source files. Use the Makefile to build the docs, like so:
make builder
where "builder" is one of the supported builders, e.g. html, latex or linkcheck.
安装sphinx-rtd-theme主题,默认的主题是很不友好的,要换一下
pip install sphinx-rtd-theme
安装完毕主题之后修改config.py配置文件主题的配置如下
html_theme = 'sphinx_rtd_theme'
操作介绍(我这里安装的目录是/html/)
1、编辑/html/source下的.rst开头的文件
# tree -L 1 (查看文件目录结构)
.
├── conf.py
├── fulu_01.rst
├── fulu_02.rst
├── fulu_03.rst
├── fulu_04.rst
├── fulu_05.rst
├── images
├── index.rst
├── _static
├── step_01.rst
├── step_02.rst
├── step_03.rst
├── step_04.rst
├── step_05.rst
├── step_06.rst
├── step_07.rst
└── _templates
3 directories, 14 files
2、看看导引文件
# cat index.rst
.. xxxxxxxxxx documentation master file, created by
sphinx-quickstart on Tue Jan 12 01:38:29 2021.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to xxxxxxx's documentation!
======================================================
.. toctree::
:maxdepth: 2
:caption: Contents:
step_01
step_02
step_03
step_04
step_05
step_06
step_07
fulu_01
fulu_02
fulu_03
fulu_04
fulu_05
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
3、make操作
编辑完成之后在/html目录下 make html即可
# make html
Running Sphinx v4.2.0
loading translations [zh-cn]... not available for built-in messages
loading pickled environment... done
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 2 source files that are out of date
updating environment: 0 added, 2 changed, 0 removed
reading sources... [100%] step_02
/html/source/step_02.rst:6: WARNING: Unexpected indentation.
/html/source/step_02.rst:10: WARNING: Unexpected indentation.
/html/source/step_02.rst:14: WARNING: Unexpected indentation.
/html/source/step_02.rst:18: WARNING: Unexpected indentation.
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
writing output... [100%] step_02
generating indices... genindex done
writing additional pages... search done
copying static files... done
copying extra files... done
dumping search index in English (code: en)... done
dumping object inventory... done
build succeeded, 4 warnings.
The HTML pages are in build/html.
每次编辑维护都需要make html一下 才可以生效
|