导出您的绘图.io在构建时使用图表,以便更容易地嵌入到文档中
mkdocs-drawio-exporter的Python项目详细描述
在绘图.ioMkDocs出口商
导出您的绘图.io更容易在文档中嵌入图表。在
快速入门
首先安装软件包:
$ pip install mkdocs-drawio-exporter
然后启用它:
^{pr2}$配置
下面的值是默认值——此部分是可选的,如果它们适合您,可以省略。在
plugins:-drawio-exporter:# Diagrams are cached to speed up site generation. The default path is# drawio-exporter, relative to the documentation directory.cache_dir:'drawio-exporter'# Path to the Draw.io executable:# * drawio on Linux# * draw.io on macOS# * or draw.io.exe on Windows# We'll look for it on your system's PATH, then default installation# paths. If we can't find it we'll warn you.drawio_executable:null# Additional Draw.io CLI argsdrawio_args:[]# Output format (see draw.io --help | grep format)format:svg# Glob pattern for matching source filessources:'*.drawio'
使用
配置好插件后,您现在可以通过简单地嵌入*.drawio
图文件来继续嵌入图像,就像您对任何图像文件的嵌入一样:
![My alt text](my-diagram.drawio)
如果使用多页文档,请在URL中附加页面索引作为锚点:
![Page 1](my-diagram.drawio#0)
插件将把图表导出到配置中指定的format
,并重写生成的页面中的<img>
标记以匹配。为了加快文档重建,生成的输出将被放入cache_dir
,然后复制到所需的目的地。仅当源关系图的修改日期比缓存的导出日期新时,才会更新缓存的映像。因此,请记住缓存是针对每个文件的—对于大型多页文档,更改一个页面将重建所有页面,这将比每个页面单独的文件慢。在
无头使用
除此之外,如果您在无头环境中运行(例如在集成中,或在Docker容器中),您可能需要确保显示服务器正在运行,并且安装了必要的依赖项。在
在Debian和Ubuntu上,应该安装依赖项:
sudo apt install libasound2 xvfb
要使用自动分配的X显示运行MkDocs,请按如下方式包装命令:
xvfb-run -a mkdocs build
在没有沙盒的情况下运行
如果您看到以下消息,则很可能您正在以root用户身份运行MkDocs:
[22:0418/231827.169035:FATAL:electron_main_delegate.cc(211)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
如果可能,考虑以非特权用户身份运行MkDocs。根据具体情况(例如在非特权容器中运行),可以通过向mkdocs.yml
添加以下选项来禁用Chrome沙盒:
plugins:-drawio-exporter:drawio_args:---no-sandbox
黑客攻击
要在编辑器中完成工作,请在此存储库的根目录中设置一个虚拟环境并安装MkDocs:
$ pip3 install --user --upgrade setuptools twine wheel
$ python3 -m venv venv
$ . venv/bin/activate
$ pip install -r requirements.txt
要以可编辑的形式将插件安装到本地MkDocs站点:
$ pip install --editable /path/to/mkdocs-drawio-exporter
请注意,如果对setup.py
中列出的entry_points
进行任何更改,则需要重复此步骤。在
使用Pythonunittest
模块运行测试:
$ python -m unittest mkdocsdrawioexporter.tests
正在升级依赖项
要升级依赖项,请安装pip-upgrader
:
. venv/bin/activatepip install -r requirements.dev.txt
然后继续更新依赖项:
pip-upgrade requirements.dev.txt
释放
构建可分发包:
$ python3 setup.py sdist bdist_wheel
将其推送到PyPI测试实例:
$ python3 -m twine upload --repository-url https://test.pypi.org/legacy/ dist/*
在虚拟环境中进行测试:
$ pip install --index-url https://test.pypi.org/simple/ --no-deps mkdocs-drawio-exporter
让我们开始吧:
$ python3 -m twine upload dist/*
- 项目
标签: