sphinx.ext.graphviz --添加graphviz图

Added in version 0.6.

此扩展允许您嵌入 Graphviz 文档中的图表。

它添加了以下指令:

.. graphviz::

嵌入graphviz代码的指令。的输入代码 dot 作为内容给出。例如::

.. graphviz::

   digraph foo {
      "bar" -> "baz";
   }

在HTML输出中,代码将呈现为PNG或SVG图像(请参见 graphviz_output_format )在LaTex输出中,代码将呈现为可嵌入的PDF文件。

还可以通过将文件名作为参数提供给 graphviz 无附加内容:

.. graphviz:: external.dot

对于sphinx中的所有文件引用,如果文件名是绝对的,则将其视为相对于源目录的文件。

在 1.1 版本发生变更: 添加了对外部文件的支持。

选项

:alt: alternate text (text)

图表的替换文本。默认情况下,图形代码用于替换文本。

Added in version 1.0.

:align: alignment of the graph (left, center or right)

图形的水平对齐。

Added in version 1.5.

:caption: caption of the graph (text)

图表的标题。

Added in version 1.1.

:layout: layout type of the graph (text)

图形的布局(例如 dotneato 等等)。还允许使用graphviz命令的路径。默认情况下, graphviz_dot 使用。

Added in version 1.4.

在 2.2 版本发生变更: 更名为 graphviz_dot

:name: label (text)

图表的标签。

Added in version 1.6.

:class: class names (a list of class names separated by spaces)

图的类名。

Added in version 2.4.

.. graph::

用于嵌入单个无向图的指令。名称作为指令参数提供,图形的内容是指令内容。这是生成 graph <name> {{ <content> }} .

例如::

.. graph:: foo

   "bar" -- "baz";

备注

将图形名不变地传递给graphviz。如果它包含非字母数字字符(例如破折号),则必须用双引号括起来。

选项

等同于 graphviz .

:alt: alternate text (text)

Added in version 1.0.

:align: alignment of the graph (left, center or right)

Added in version 1.5.

:caption: caption of the graph (text)

Added in version 1.1.

:layout: layout type of the graph (text)

Added in version 1.4.

在 2.2 版本发生变更: 更名为 graphviz_dot

:name: label (text)

Added in version 1.6.

:class: class names (a list of class names separated by spaces)

图的类名。

Added in version 2.4.

.. digraph::

用于嵌入单个有向图的指令。名称作为指令参数提供,图形的内容是指令内容。这是生成 digraph <name> {{ <content> }} .

例如::

.. digraph:: foo

   "bar" -> "baz" -> "quux";

选项

等同于 graphviz .

:alt: alternate text (text)

Added in version 1.0.

:align: alignment of the graph (left, center or right)

Added in version 1.5.

:caption: caption of the graph (text)

Added in version 1.1.

:layout: layout type of the graph (text)

Added in version 1.4.

在 2.2 版本发生变更: 更名为 graphviz_dot

:name: label (text)

Added in version 1.6.

:class: class names (a list of class names separated by spaces)

图的类名。

Added in version 2.4.

还有这些配置值:

graphviz_dot

用于调用的命令名 dot . 默认值为 'dot' ;如果 dot 不在可执行搜索路径中。

由于此设置不可从一个系统移植到另一个系统,因此通常将其设置为 conf.py 相反,把它放在 sphinx-build 命令行通过 -D 最好选择如下:

sphinx-build -M html -D graphviz_dot=C:\graphviz\bin\dot.exe . _build
graphviz_dot_args

作为列表提供给点的其他命令行参数。默认值为空列表。这是通过点设置全局图形、节点或边缘属性的正确位置 -G-N-E 选项。

graphviz_output_format

生成HTML文件时graphviz的输出格式。这必须是 'png''svg' ;默认为 'png' .如果 'svg' 被使用,为了使URL链接正常工作,一个适当的 target 必须设置属性,例如 "_top""_blank" . 例如,下图中的链接应在SVG输出中工作:::

.. graphviz::

     digraph example {
         a [label="sphinx", href="https://www.sphinx-doc.org/", target="_top"];
         b [label="other"];
         a -> b;
     }

Added in version 1.0: 以前,输出总是PNG。