通过脚本或命令渲染图像的sphinx扩展
sphinxcontrib-cmd2img的Python项目详细描述
用于呈现命令体生成的图像/图形的sphinx扩展。
author: | “Yongping Guo”<guoyoooping@163.com> |
---|
一。安装和设置
PIP安装SphinxContrib-CMD2IMG
只需将sphinxcontrib.cmd2img添加到 conf.py文件。例如:
extensions = ['sphinxcontrib.cmd2img']
2.介绍和示例
在rst中,我们使用image和figure指令在 目标HTML文档,这给了我们很多便利。事实上我们可以 比那更可怕。
有时某些命令会转换或生成图像,我们希望 直接高效地渲染,例如:
ditaa是一个小型的命令行实用程序,可以转换绘制的图表 使用ascii艺术(包含类似行的字符的图形) 像/-),变成适当的位图图形。我们可以用下面的 用于呈现由DITAA生成的图像的指令:
.. cmd2img:: ditaa +--------+ +-------+ +-------+ | | --+ ditaa +--> | | | Text | +-------+ |diagram| |Document| |!magic!| | | | {d}| | | | | +---+----+ +-------+ +-------+ : ^ | Lots of work | +-------------------------+
或者使用以下指令将其呈现为图形,对于图形,我们可以 添加标题:
.. cmd2fig:: ditaa :caption: figure 1. An example to use ditaa to render a figure +--------+ +-------+ +-------+ | | --+ ditaa +--> | | | Text | +-------+ |diagram| |Document| |!magic!| | | | {d}| | | | | +---+----+ +-------+ +-------+ : ^ | Lots of work | +-------------------------+
另一个例子是gnuplot:
.. cmd2img:: gnuplot set y2tics -100, 10 set ytics nomirror plot sin(1/x) axis x1y1, 100*cos(x) axis x1y2
另一个例子是convert,它将在目标中呈现为gif:
.. cmd2img:: convert rose: -duplicate 29 -virtual-pixel Gray -distort SRT '%[fx:360.0*t/n]' -set delay '%[fx:t == 0 ? 240 : 10]' -loop 0 rose.gif
另一个例子:
.. cmd2img:: dot -T png digraph example { a [label="sphinx", href="http://www.sphinx-doc.org/en/master/usage/extensions/index.html", target="_top"]; b [label="other"]; a -> b; }
3个选项
SphinxContrib-CMD2IMG提供了一些易于使用的选项。
3.1命令选项
对于命令选项,应将其添加到命令之后,例如:
.. cmd2fig:: ditaa --no-antialias :caption: figure 2. illustration for command option. +--------+ +-------+ +-------+ | | --+ ditaa +--> | | | Text | +-------+ |diagram| |Document| |!magic!| | | | {d}| | | | | +---+----+ +-------+ +-------+ : ^ | Lots of work | +-------------------------+
3.2 SphinxContrib-CMD2IMG选项
DITAA选项:
show_source: for text generated iamge, if the source code is shown. watermark: Add water mark in the image gravity: watermark gravity, see detail imagematick command convert -draw location: watermark location, see detail imagematick command convert -draw fill: watermark contention, see detail imagematick command convert -draw pointsize: watermark pointsize, see detail imagematick command convert -draw font: watermark font, see detail imagematick command convert -draw
例如:
.. cmd2img:: gnuplot :width: 300 :watermark: text 0,0 "gnuplot test" set y2tics -100, 10 set ytics nomirror plot sin(1/x) axis x1y1, 100*cos(x) axis x1y2
5个。许可证
gplv3
6.更改日志
0.1初始上载。 0.2更正小错误