sphinx.ext.graphviz -- 添加Graphviz图

在 0.6 版本加入.

此插件允许嵌入 Graphviz 图表到你的文档。

重要

Graphviz must be present on your machine; please refer to the official instructions if it is not the case.

它添加了以下指令:

.. 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)

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

在 1.0 版本加入.

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

图形的水平对齐。

在 1.5 版本加入.

:caption: caption of the graph (text)

图表的标题。

在 1.1 版本加入.

:layout: layout type of the graph (text)

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

在 1.4 版本加入.

在 2.2 版本发生变更: graphviz_dot 重命名

:name: label (text)

图形的标签。

在 1.6 版本加入.

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

图形的类名。

在 2.4 版本加入.

.. graph::

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

例如:

.. graph:: foo

   "bar" -- "baz";

备注

图形名被原封不动地传递给Graphviz。如果它包含非字母数字字符(如破折号),则必须双引号。

选项

graphviz 一样

:alt: alternate text (text)

在 1.0 版本加入.

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

在 1.5 版本加入.

:caption: caption of the graph (text)

在 1.1 版本加入.

:layout: layout type of the graph (text)

在 1.4 版本加入.

在 2.2 版本发生变更: graphviz_dot 重命名

:name: label (text)

在 1.6 版本加入.

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

图形的类名。

在 2.4 版本加入.

.. digraph::

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

例如:

.. digraph:: foo

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

选项

graphviz 一样

:alt: alternate text (text)

在 1.0 版本加入.

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

在 1.5 版本加入.

:caption: caption of the graph (text)

在 1.1 版本加入.

:layout: layout type of the graph (text)

在 1.4 版本加入.

在 2.2 版本发生变更: graphviz_dot 重命名

:name: label (text)

在 1.6 版本加入.

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

图形的类名。

在 2.4 版本加入.

还有以下配置值:

graphviz_dot
类型:
str
默认:
'dot'

调用 dot 的命令名称。如果 dot 不在可执行文件搜索路径中,您可能需要将其设置为完整路径。

由于此设置在系统之间不可移植,因此通常设置它是没有用的 配置文件;相反,在 sphinxbuild 命令行中通过 -D 选项给出它应该更可取,如下所示:

sphinx-build -M html -D graphviz_dot=C:\graphviz\bin\dot.exe . _build
graphviz_dot_args
类型:
Sequence[str]
默认:
()

以列表形式,向点提供的其他命令行参数。这是通过点的 -G-N-E 选项设置全局图形、节点或边属性的正确位置。

graphviz_output_format
类型:
'png' | 'svg'
默认:
'png'

构建HTML文件时Graphviz的输出格式。这必须是 'png''svg' 。如果使用 '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;
     }

在 1.0 版本加入: 以前,输出总是PNG。