Sphinx中支持Plantuml

By | 4月 4, 2017

需要在Python中安装一个lib,叫sphinxcontrib-plantuml,官网:https://pypi.python.org/pypi/sphinxcontrib-plantuml

1. 安装sphinxcontrib-plantuml

1.1 pip安装

pip install sphinxcontrib-plantuml

1.2 下载安装

点击官网页面“Download”链接下载。

下载完,解压,运行命令:

python setup.py install

2. 修改Sphinx文档配置

找到文档目录中的conf.py文件,添加extension和plantuml调用指令。

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.autodoc']
extensions = ['sphinxcontrib.plantuml']

plantuml = 'java -jar plantuml.2017.08.jar'

3. 基本使用

3.1 直接写PlantUML

.. uml::

   Alice -> Bob: Hi!
   Alice <- Bob: How are you?

3.2 引入一个PlantUML文件

.. uml:: external.uml

3.3 定义height, width, scale和align

.. uml::
   :scale: 50 %
   :align: center

   Foo <|-- Bar

3.4 定义一个标题

.. uml::
   :caption: Caption with **bold** and *italic*
   :width: 50mm

   Foo <|-- Bar