生成文档过程
安装Sphinx
Sphinx是用Python编写的,因此你需要先安装Python。安装Python后,可以使用pip(Python的包管理工具)来安装Sphinx。
pip install sphinx
准备.rst文件
确保你已经有了一个或多个.rst文件,这些文件包含了你想要生成的文档的内容。这些文件应该按照ReStructuredText的语法编写。
创建项目
使用Sphinx创建一个新的项目,或者如果你已经有一个项目,则直接进入该项目目录。在项目目录中,使用Sphinx的sphinx-quickstart
命令来生成项目的基本结构和配置文件。例如:
sphinx-quickstart
这个命令会引导你通过一系列问题来配置你的项目,包括项目名称、作者、版本等。完成这些步骤后,Sphinx会在你的项目目录中生成一些文件和文件夹,包括conf.py(配置文件)、index.rst(主文档文件)等。
编辑.rst文件和配置文件
根据你的需求,编辑index.rst和其他.rst文件,以包含你想要的文档内容。同时,你可能还需要编辑conf.py文件来配置你的项目,比如设置主题、扩展等。
生成文档
在项目目录中,使用Sphinx的make
命令(在Windows上可能是make.bat
)来生成文档。可以通过指定不同的目标来生成不同类型的文档。例如:
make html
生成的HTML文档将位于_build/html目录下。
nuttx文档实例
nuttx/Documentation下有index.rst,所以不用创建项目,
cd nuttx/Documentation
在nuttx/Documentation目录下,使用Sphinx的make
命令可以直接生成文档。
$ make
Sphinx v7.1.2
Please use `make target' where target is one of
html to make standalone HTML files
dirhtml to make HTML files named index.html in directories
singlehtml to make a single large HTML file
pickle to make pickle files
json to make JSON files
htmlhelp to make HTML files and an HTML help project
qthelp to make HTML files and a qthelp project
devhelp to make HTML files and a Devhelp project
epub to make an epub
latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter
latexpdf to make LaTeX and PDF files (default pdflatex)
latexpdfja to make LaTeX files and run them through platex/dvipdfmx
text to make text files
man to make manual pages
texinfo to make Texinfo files
info to make Texinfo files and run them through makeinfo
gettext to make PO message catalogs
changes to make an overview of all changed/added/deprecated items
xml to make Docutils-native XML files
pseudoxml to make pseudoxml-XML files for display purposes
linkcheck to check all external links for integrity
doctest to run all doctests embedded in the documentation (if enabled)
coverage to run coverage check of the documentation (if enabled)
clean to remove everything in the build directory
make html生成的HTML文档将位于_build/html
目录下。
make html
$ make html
Removing everything under '_build'...
Running Sphinx v7.1.2
building [mo]: targets for 0 po files that are out of date
writing output...
building [html]: targets for 1097 source files that are out of date
updating environment: [new config] 1097 added, 0 changed, 0 removed
reading sources... [100%] substitutions
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
copying downloadable files... [100%] platforms/xtensa/esp32s2/boards/esp32s2-saola-1/tone.wav
copying static files... done
copying extra files... done
done
writing output... [100%] substitutions
generating indices... genindex done
writing additional pages... search done
copying images... [100%] _static/images/menuconfig-debug.png
dumping search index in English (code: en)... done
dumping object inventory... done
build succeeded.
The HTML pages are in _build/html.