6.3. 使用PlantUML绘图#
6.3.1. Installation#
sudo apt install -y python3-sphinxcontrib.plantuml plantuml
这个扩展需要安装,其发布地址为: https://pypi.org/project/sphinxcontrib-plantuml/
6.3.2. Usage#
Add sphinxcontrib.plantuml to your extensions list in your conf.py:
extensions = [
'sphinxcontrib.plantuml',
]
You may also need to specify the plantuml command in your conf.py:
plantuml = 'java -jar /path/to/plantuml.jar'
Instead, you can install a wrapper script in your PATH:
cat <<EOT > /usr/local/bin/plantuml
!/bin/sh -e
java -jar /path/to/plantuml.jar "$@"
EOT
chmod +x /usr/local/bin/plantuml
Then, write PlantUML text under the .. uml:: directive:
or specify path to an external PlantUML file:
You can specify height, width, scale and align:
You can also specify a caption:
Caption with bold and italic
For details, please see PlantUML documentation.
6.3.3. Configuration#
plantuml : Path to plantuml executable. (default:
plantuml
)- plantuml_output_formatType of output image for HTML renderer. (default:
png
) png : generate only .png inside </img>
svg : generate .svg inside <object/> with .png inside </img> as a fallback . When svg is inside <object/> it will always render full size, possibly bigger than the container. When svg is inside <img/> it will respect container size and scale if necessary.
svg_img : generate only .svg inside <img/> (browser support)
svg_obj : generate only .svg inside <object/> (browser support)
none : do not generate any images (ignore uml directive)
- plantuml_output_formatType of output image for HTML renderer. (default:
- plantuml_latex_output_formatType of output image for LaTeX renderer. (default:
png
) Because embedded png looks pretty bad, it is recommended to choose pdf for pdflatex or eps for platex. eps : generate .eps (not supported by pdflatex)
pdf : generate .eps and convert it to .pdf (requires epstopdf)
png : generate .png
tikz : generate .latex in the TikZ format
none : do not generate any images (ignore uml directive)
- plantuml_latex_output_formatType of output image for LaTeX renderer. (default:
plantuml_epstopdf : Path to epstopdf executable. (default:
epstopdf
)plantuml_syntax_error_image : Should plantuml generate images with render errors. (default:
False
)plantuml_cache_path : Directory where image cache is stored. (default:
_plantuml
)plantuml_batch_size : (EXPERIMENTAL) Run plantuml command per the specified number of images. (default:
1
)
If enabled, plantuml documents will be first written to the cache directory, and rendered in batches. This eliminates bootstrapping overhead of Java runtime and allows plantuml to leverage multiple CPU cores.
To enable batch rendering, set the size to 100-1000.