sphinx+reStructuredText制作文档

2023-05-16

1 spinx简介

Sphinx 是一种文档工具,它可以令人轻松的撰写出清晰且优美的文档, 由 Georg Brandl 在BSD 许可证下开发. 新版的Python文档 就是由Sphinx生成的,
并且它已成为Python项目首选的文档工具,同时它对 C/C++ 项目也有很好的支持; 并计划对其它开发语言添加特殊支持. 本站当然也是使用 Sphinx 生成的,
它采用reStructuredText! Sphinx还在继续开发. 下面列出了其良好特性,这些特性在Python官方文档中均有体现:

  • 丰富的输出格式: 支持 HTML (包括 Windows 帮助文档), LaTeX (可以打印PDF版本), manual pages(man 文档), 纯文本
  • 完备的交叉引用: 语义化的标签,并可以自动化链接函数,类,引文,术语及相似的片段信息
  • 明晰的分层结构: 可以轻松的定义文档树,并自动化链接同级/父级/下级文章
  • 美观的自动索引: 可自动生成美观的模块索引
  • 精确的语法高亮: 基于 Pygments 自动生成语法高亮
  • 开放的扩展: 支持代码块的自动测试,并包含Python模块的自述文档(API docs)等

2 rst简介

reStructuredText 是扩展名为.rst的纯文本文件,含义为"重新构建的文本",也被简称为:RST或reST;是Python编程语言的Docutils项目的一部分,
Python Doc-SIG (Documentation Special Interest Group)。该项目类似于Java的JavaDoc或Perl的POD项目。
Docutils 能够从Python程序中提取注释和信息,格式化成程序文档。

.rst 文件是轻量级标记语言的一种,被设计为容易阅读和编写的纯文本,并且可以借助Docutils这样的程序进行文档处理,

也可以转换为HTML或PDF等多种格式,或由Sphinx-Doc这样的程序转换为LaTex、man等更多格式

3 环境准备

3.1 安装python

我是在anaconda安装的python,官方下载地址是https://www.anaconda.com/download/#windows ,我写这边博文的时候最新版本是https://repo.continuum.io/archive/Anaconda3-5.0.1-Windows-x86_64.exe。

注意: 安装的时候勾选add Anaconda to my Path environment variable选项

3.2 文本编辑软件安装

这里我使用的是vscode,官方下载地址是https://code.visualstudio.com/,我写这篇博文的最新版本下载地址是https://go.microsoft.com/fwlink/?Linkid=852157

3.3 sphinx的安装

具体可以参考:http://www.sphinx-doc.org/en/stable/tutorial.html#install-sphinx

安装sphinx


C:\Users\test>pip install sphinx  

安装 restructuredtext-lint


C:\Users\test>pip install restructuredtext-lint  

3.4 vscode环境配置

打开vscode软件,【查看】>【扩展】输入restructuredText 安装这个软件即可。

重启下vscode使得restructuredText生效。

4 开始sphinx和rst工作

4.1 创建并打开工程目录

常见一个工程目录(c:/github/test),并使用vscode打开工程目录 ,【文件】->【打开文件夹】

4.2 使用shhinx-quickstart建立工程

打开终端 ,【查看】->【终端】,输入shpinx-quickstart命令

shpinx-quichstart命令具体参考官方:http://www.sphinx-doc.org/en/stable/invocation.html#invocation


Windows PowerShell
版权所有 (C) Microsoft Corporation。保留所有权利。

PS C:\github\test> sphinx-quickstart
Welcome to the Sphinx 1.6.3 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 [.]:

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 [_]:

The project name will occur in several places in the built documentation.
> Project name: Test
> Author name(s): Zhaojiedi1992

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 []: v1.0
> Project release [v1.0]:

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]: en

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]:

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]:
> intersphinx: link between Sphinx documentation of different projects (y/n) [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]:
> ifconfig: conditional inclusion of content based on config values (y/n) [n]:
> viewcode: include links to the source code of documented Python objects (y/n) [n]:
> githubpages: create .nojekyll file to publish the document on GitHub pages (y/n) [n]:

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]:
> Create Windows command file? (y/n) [y]:

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.

4.3 打开编码目录

在终端输入code source ,进入source目录编辑


PS C:\github\test> code source  

我们可以看到又打开了一个vscode窗口。目录为source的,我们可以点击上面的有个预览按纽的。可以方便我们预览的

4.4 开始编写文档

这里我就不写了。 可以直接从这个地方下载https://github.com/zhaojiedi1992/My_Study_ReStructuredText,点击Clone or download按纽即可下载源文档。

然后复制 index.rst文件和 images,基础语法,中级语法三个目录到source目录中去。

具体的文档编写可以参考如下地址: 

  •   sphinx对rst文档的帮助文档: http://www.sphinx-doc.org/en/stable/rest.html
  •   spinx对rst文档的中文帮助文档:http://zh-sphinx-doc.readthedocs.io/en/latest/rest.html
  •        我自己的对与rst的学习笔记  (实用版): http://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_liunx_30_python_restructuredtext.html
  •   rst的官文帮助文档:http://docutils.sourceforge.net/rst.html

4.5 设置主题

我不习惯官方的主题,喜欢sphinx_rtd_theme主题

官方内置主题参考:http://www.sphinx-doc.org/en/stable/theming.html#builtin-themes


PS C:\github\test\source> pip install sphinx_rtd_theme  

安装完毕后,修改conf.py文件,保存下。


html_theme = 'sphinx_rtd_theme'  

4.6 生成文档

在工程目录(非source目录),执行make命令


PS C:\github\test> ./make clean
PS C:\github\test> ./make html  

注意:这里生成的是html格式的。当然可以生成dirhtml,singlehtml,epub,devhelp,latex,man,texinfo,text等多种格式。

详细make命令参考官方:http://www.sphinx-doc.org/en/stable/invocation.html#makefile-options

4.7 预览

生成的htm目录在工程的build/html目录

双击html目录下的index.html完成预览

 

5 发布出去

这个发布就比较多了。简单是可以把html目录挂到iis,或者apache,httpd对应的网页目录即可。

这里我使用redthedoc的方法来做。

5.1 注册账号

在redthedoc注册一个账号

5.2 导入项目

网址: https://readthedocs.org/dashboard/import/?

导入项目通过github方式。可以把github的库直接导入,非常方便。

我导入我的一个github项目my-study-restructuredtext

5.3构建

导入完毕后有个Build按纽,点击就可以完成构建了。 

注意:这个构建一次之后。后续我们在github上的提交不用在重新构建的。它会自动保存更新的,可能需要在push后等1-2分钟。

5.4 访问

 构建完毕可以点击阅读文档的按纽了。

具体访问: http://my-study-restructuredtext.readthedocs.io/en/latest/

6 参考文档 

sphinx中文帮助文档:http://zh-sphinx-doc.readthedocs.io/en/latest/contents.html

spinx英文帮助文档:http://www.sphinx-doc.org/en/stable/contents.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

sphinx+reStructuredText制作文档 的相关文章

  • 利用iftop查看网络带宽使用情况

    2019独角兽企业重金招聘Python工程师标准 gt gt gt 利用iftop查看服务器实时流量 yum install y gcc flex byacc libpcap ncurses ncurses devel libpcap de
  • matlab程序改为m文件名,在MATLAB中,程序文件的扩展名为.m,所以程序文件也称为M文件...

    在MATLAB中 xff0c 程序文件的扩展名为 m xff0c 所以程序文件也称为M文件 答 xff1a 磷酸果糖激酶 2催化6 磷酸果糖生成的产物是 答 xff1a 2 xff0c 6 二磷酸果糖 人类行为的经济学分析 的作者是 答 x
  • 学习ASP.NET Core Razor 编程系列十八——并发解决方案

    学习ASP NET Core Razor 编程系列目录 学习ASP NET Core Razor 编程系列一 学习ASP NET Core Razor 编程系列二 添加一个实体 学习ASP NET Core Razor 编程系列三 创建数据
  • Kubernetes运行监控-使用Helm快速部署Prometheus和Grafana

    2019独角兽企业重金招聘Python工程师标准 gt gt gt Kubernetes运行监控 使用Helm快速部署Prometheus和Grafana 使用Helm快速部署Pormetheus和Grafana非常方便 xff0c 很多手
  • linux交叉编译c++

    下载g 43 43 交叉编译工具链 sudo apt install g 43 43 arm linux gnueabihf 测试程序 include lt iostream gt using namespace std int main
  • 因子分析factor analysis_spss运用_python建模(推荐AAA)

    sklearn实战 乳腺癌细胞数据挖掘 xff08 博主亲自录制视频 xff09 https study 163 com course introduction htm courseId 61 1005269003 amp utm camp
  • 清除ListBox的列表项(删除所有项目)

    如何清除ListBox的列表项 删除所有项目 xff0c 今天开发程序时 xff0c 有尝试使用此功能 一开始并不是很顺利 循环所有item去做remove时 xff0c 需要执行两次才可以完成清除 debug进行步进跟踪 xff0c 发现
  • SVN查看所有日志提交记录

    1 svn默认显示最近一周的文件提交和修改记录 xff0c 怎么查看更长时间的日志记录呢 xff1f 2 TortoiseSVN 3 点击show all 或者NEXT 100 xff0c 就可显示更长时间的文件提交记录
  • Nearest neighbor graph | 近邻图

    最近在开发一套自己的单细胞分析方法 xff0c 所以copy paste事业有所停顿 实例 xff1a R eNetIt v0 1 1 data ralu site Saturated spatial graph sat graph lt
  • 手把手教你实现一个简单的编译器

    手把手教你实现一个简单的编译器 1 概述 今天我们将学习开发一个编译器 xff0c 但是呢 xff0c 这个编译器并不是说什么都能都编译 xff0c 它只是一个超级小的编译器 xff0c 主要用于说明编译器的一些基本的原理 我们这个编译器可
  • 查看struts版本号

    2019独角兽企业重金招聘Python工程师标准 gt gt gt struts版本信息查看方法 xff1a 查看lib中的 struts2 core jar META INF MANIFEST MF 找到Implementation Ve
  • R语言读取大数据 data.table包 fread函数

    gt setwd 34 D R Tardy 34 gt library data table data table 1 9 6 For help type data table or https github com Rdatatable
  • Android中读取文本文件中内容的方法

    这几天在项目开发中 xff0c 要读取文本文件中内容的 xff0c 因此写了个读取文本文件中内容的方法 xff0c 代码如下 xff1a 读取文本文件中的内容 public static String ReadTxtFile String
  • Error creating bean with name 'objectMapperConfigurer' defined in class path resource

    转载于 https www cnblogs com qianjinyan p 10879065 html
  • C#实现Windows 服务的制作安装和删除[转]

    关于C 实现windows服务的制作与安装还有删除 运行Visual Studio NET xff0c 建立一个C 的Windows服务项目 主程序代码 xff1a 以下是引用片段 xff1a Code using System using
  • 相机与IMU联合标定

    相机与IMU联合标定 1 imu utils 标定IMU的内参1 1 安装环境1 2 录制IMU数据集 2 kalibr 标定工具2 1 安装2 2 校准相机的内外参2 3 校准相机与IMU外参 总结参考资料 1 imu utils标定IM
  • matlab练习程序(寻找凸包,Graham扫描法)

    我不太清楚这个凸包在图像处理中到底会怎样的运用 xff0c 因为这个好像更多的是计算几何或是图形学里面的东西 不过作为一个算法 xff0c 我感觉还是有必要研究一下的 我主要的参考资料是 算法导论 的33 3和这个博客 代码在这里 xff0
  • 1

    stage 1 xff1a 尝试直接使用Adobe acrobat xff0c foxit阅读器 xff0c 以及CAJ等PDF阅读器 xff0c 尝试使用CAJ是因为CAJ有文字识别功能 xff0c 但是对于加密的文档 xff0c 依然是
  • Python自动化备份系统及网站

    随着目前IT迅猛的发展 xff0c 自动化运维对于Linux运维人员也越来越重要 xff0c 传统的运维方式靠大量的人力 xff0c 现在也逐渐转向自动化运维 xff0c 我们常见的跟自动化有关的软件有哪些呢 今天我们来简单列举一下 xff
  • AI 黑箱难题怎么破?基于神经网络模型的算法使机器学习透明化

    编者按 xff1a 人们可以训练人工智能 xff08 AI xff09 和机器人完成任务 xff0c 但整个过程在黑箱中运作 我们并不知道 AI 和机器人是如何决策的 一家名为 OptimizingMind 的初创公司想要解决这个问题 这篇

随机推荐

  • 技术面试介绍

    内容 xff1a 1 技术面试的形式 2 技术面试的大致环节 3 技术面试应具备的素质 4 技术面试的经验建议 参考 xff1a 剑指offer 第二版 第一章 Java程序员面试笔试宝典 第一章 第二章 1 技术面试的形式 技术面试大致上
  • 今天是 Java 诞生日,Java 24 岁了!

    2019独角兽企业重金招聘Python工程师标准 gt gt gt 今天是 Java 诞生日 xff0c Java 今年 24 岁了 xff0c 比栈长还年轻 还有得搞 xff0c 别慌 xff01 作为一名Java语言的学习者 xff0c
  • [原创]求两个经纬度之间的距离

    经常要根据两个经纬度值 求它们之间的距离 delphi实现代码 xff1a 求两个经纬度之间的距离 function Distince const lon1 lat1 lon2 lat2 double double var alpha1 a
  • cmake的命令execute_process

    execute process COMMAND lt cmd1 gt args1 COMMAND lt cmd2 gt args2 WORKING DIRECTORY lt directory gt TIMEOUT lt seconds g
  • php 输出数组内容_php数组怎么输出

    PHP数组的输出方式有两种 xff1a print r 函数和var dump 函数 1 print r 利用 print r 函数可以打印输出整个数组内容及结构 xff0c 按照一定格式显示键和元素 注意 print r 函数不仅是只用于
  • VNC常用操作及常见问题解决办法汇总

    VNC登录用户缺省是root xff0c 但在安装oracle时必须用oracle用户的身份登录 xff0c 下面我们就以oracle为例说明如何配置VNC xff0c 从而可以使用不同的用户登录到主机 步骤描述如下 xff1a 步骤一 x
  • Xsens 在ROS环境下读取数据

    Xsens 在ROS环境下读取数据 1 Xsens 参数配置2 Xsens ROS环境下读取数据2 1 安装ROS二进制包2 2 Xsens修改rule文件2 3 启动节点 参考资料 1 Xsens 参数配置 软件可以在官网上进行下载 1
  • 交换机***查询篇

    如何确定 类型 当设备遭受 时 xff0c 通常伴随着如下现象 xff1a 用户无法获取ARP 用户上线成功率较低 用户无法访问网络 l严重时可能导致设备上所有用户都无法正常访问网络 当大量用户或固定某个端口下的所有用户出现上述现象时 xf
  • tomcat部署war包访问显示404

    在eclipse导出的maven项目war包 xff0c 放到tomcat下启动 xff0c 顺利启动且无报错 xff0c 但是浏览器访问该项目时显示404 原因 xff1a 未在server xml中配置这几个项目 xff0c 导致服务器
  • Pycharm: 代码跳转如何回退 (小技巧)

    背景 玩Python已经有段时间了 一般都是通过vim和Pycharm来开发 真心觉得这两个是神器 Vim神器暂且不说 今天来分享Pycharm的一个小技巧 用Pycharm的童鞋都知道 它有个跳转的功能 可以让我们在想深入了解某个函数 库
  • 最近沉迷美女图片无法自拔,所以我决定用PHP扒海量妹子图

    为什么80 的码农都做不了架构师 xff1f gt gt gt 学习PHP 43 MySQL制作WEB应用有一阵子了 xff0c 没有上过学所以只能学习到CURD的地步 最近对国产美女图片 私房写真特别感兴趣 xff0c 什么周妍希 刘飞儿
  • elementui的loading啊。。。踩坑了。。。

    为什么80 的码农都做不了架构师 xff1f gt gt gt 总结如下 xff1a 1 elementui的loading其实是fullscreen才是全局唯一 xff0c 不然会Loading service一次创建一次实例 2 ele
  • a padding to disable MSIE and Chrome friendly error page 填充禁用MSIE铬友好的错误页面

    一个网页在用户登录后 xff0c 应该自动刷新后 xff0c 显示登录用户信息 xff0c 但是没有自动刷新反而报错 xff0c 手动刷新后显示正常 显示如下 xff1a 检查代码 xff1a 可能原因 xff1a 文件读写权限 权限和用户
  • 边缘检测:Canny算子,Sobel算子,Laplace算子

    1 canny算子 Canny边缘检测算子是John F Canny于 1986 年开发出来的一个多级边缘检测 算法 更为重要的是 Canny 创立了边缘检测计算理论 xff08 Computational theory ofedge de
  • ProtocolException : 已超过传入消息(65536)的最大消息大小配额。

    SilverLight调用WCF xff0c 提交的是一个List lt Linq2SqlEntity gt xff1b 当List中数据量不大的时候 xff0c 不会报错 xff1b 当数据量稍微大一点儿 xff0c 就会出现这个错误 发
  • 最简单的限制edit输入

    procedure TForm1 Edt NumKeyPress Sender TObject var Key Char begin If not key in 48 57 then begin key 61 0 ShowMessage 3
  • 构建安全的数据访问-异常管理(八)

    异常条件可能会由配置错误 代码中的错误或恶意输入引起 如果没有正确的异常管理 xff0c 这些条件可能会透露有关数据源位置和特性的敏感信息 xff0c 以及有价值的连接详细信息 下面的建议适用于数据访问代码 xff1a 捕获和记录 ADO
  • 开源自主导航小车MickX4(四)底盘URDF模型

    开源自主导航小车MickX4 xff08 四 xff09 底盘URDF模型 1 底盘URDF模型1 1 URFD语法1 2 基于URDF语法绘制机器人1 3 URDF文件加载stl模型 2 绘制机器人URDF模型参考资料 1 底盘URDF模
  • 中国移动5G测试路线图

    中国移动通信研究院首席科学家易芝玲博士表示 xff0c 中国移动5G技术更新的目标是实现提供高分辨率视频的传输 xff0c 2020年中国移动将推出真正的5G商用服务 谈到中国移动目前5G测试的进展 xff0c 易芝玲介绍说 xff0c 中
  • sphinx+reStructuredText制作文档

    1 spinx简介 Sphinx 是一种文档工具 xff0c 它可以令人轻松的撰写出清晰且优美的文档 由 Georg Brandl 在BSD 许可证下开发 新版的Python文档 就是由Sphinx生成的 xff0c 并且它已成为Pytho