【问题标题】:Embed a plantuml diagram somewhere in a docstring (with the Sphinx plantuml extension)在文档字符串的某处嵌入植物图(使用 Sphinx 植物扩展)
【发布时间】:2020-12-15 09:43:57
【问题描述】:

我安装了 sphinxcontrib-plantuml 扩展,如果我运行 HTML 构建器,它可以正常工作,例如使用以下 testmodule.rst 文件对应 testmodule.py 文件:

testmodule module
=================

.. automodule:: testmodule
    :members:
    :undoc-members:
    :show-inheritance:

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

这会在文档的最后添加 UML 图。不幸的是,我没有找到如何在文档中的任何位置嵌入 UML 图,例如在方法文档字符串块的中间某处。

有人知道怎么做吗?

【问题讨论】:

  • 您是否尝试在文档字符串中添加 UML 图?发生了什么?

标签: python-sphinx docstring plantuml


【解决方案1】:

直接在文档字符串部分添加 UML 图对我不起作用。 但以下对我有用:

  1. 将植物代码放在单独的文件中,例如图.uml:
@startuml
   Alice -> Bob: Hi!
   Alice <- Bob: How are you?
@enduml
  1. 在文档字符串中的所需位置添加带有文件名的 plantuml 指令。例如:
def example():
    """
    some text

    .. uml:: diagram.uml

    some more text 
    """
    ...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-22
    • 2019-12-10
    相关资源
    最近更新 更多