Giter Club home page Giter Club logo

mkdocs-drawio-exporter's Introduction

Diagrams.net (Draw.io) Exporter for MkDocs

Exports your Draw.io diagrams at build time for easier embedding into your documentation.


Quick start

First install the package:

$ pip install mkdocs-drawio-exporter

Then enable it:

plugins:
    - drawio-exporter

Configuration

For the default configuration, just add the plugin to the plugins key:

plugins:
    - drawio-exporter

You can override the default configuration; values shown are defaults:

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 args
        #   * --embed-svg-images will embed external images in SVGS, if format is "svg".
        drawio_args: []
        # Output format (see draw.io --help | grep format)
        format: svg
        # Embed format
        #   * The default is to embed via the <img> tag, only rewriting the
        #     value of the src attribute.
        #   * Consider <object type="image/svg+xml" data="{img_src}"></object>
        #     to enable interactive elements (like hyperlinks) in SVGs.
        #   * Consider {content} to inline SVGs into documents directly, useful
        #     for styling with CSS, preserving interactivity, and improving
        #     search by indexing diagram text.
        embed_format: '{img_open}{img_src}{img_close}'
        # Glob pattern for matching source files
        sources: '*.drawio'

Usage

With the plugin configured, you can now proceed to embed images by simply embedding the *.drawio diagram file as you would with any image file:

![My alt text](my-diagram.drawio)

If you're working with multi-page documents, append the index of the page as an anchor in the URL:

![Page 1](my-diagram.drawio#0)

The plugin will export the diagram to the format specified in your configuration and will rewrite the <img> tag in the generated page to match. To speed up your documentation rebuilds, the generated output will be placed into cache_dir and then copied to the desired destination. The cached images will only be updated if the source diagram's modification date is newer than the cached export. Thus, bear in mind caching works per file - with large multi-page documents a change to one page will rebuild all pages, which will be slower than separate files per page.

GitHub Actions

See this guide.

Headless usage

In addition to the above, if you're running in a headless environment (e.g. in integration, or inside a Docker container), you may need to ensure a display server is running and that the necessary dependencies are installed.

On Debian and Ubuntu, the following should install the dependencies:

sudo apt install libasound2 xvfb

To run MkDocs with an automatically assigned X display, wrap the command as follows:

xvfb-run -a mkdocs build

Running without the sandbox

If you're seeing messages like the following it's likely that you're running MkDocs as root:

[22:0418/231827.169035:FATAL:electron_main_delegate.cc(211)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.

If possible, consider running MkDocs as a non-privileged user. Depending on the circumstances (e.g. running within an unprivileged container) it may be appropriate to disable the Chrome sandbox by adding the following option to mkdocs.yml:

plugins:
    - drawio-exporter:
        drawio_args:
            - --no-sandbox

Hacking

To get completion working in your editor, set up a virtual environment in the root of this repository and install MkDocs:

$ pip3 install --user --upgrade wheel
$ pipx install twine
$ poetry install

To install the plugin onto a local MkDocs site in editable form:

$ poetry add --editable /path/to/mkdocs-drawio-exporter

Note that you'll need to repeat this step if you make any changes to the [tool.poetry.plugins.*] sections listed in pyproject.toml.

Run the tests with the test script:

$ poetry run test

Upgrading dependencies

To upgrade the dependencies, first make any necessary changes to the constraints expressed in the [tool.poetry.dependencies] section of pyproject.toml, then have Poetry update them:

$ poetry update

Releasing

Build the distributable package:

$ poetry build

Push it to the PyPI test instance:

$ twine upload --repository-url https://test.pypi.org/legacy/ dist/*

Test it inside a virtual environment:

$ pip install --index-url https://test.pypi.org/simple/ --no-deps mkdocs-drawio-exporter

Let's go live:

$ twine upload dist/*

mkdocs-drawio-exporter's People

Contributors

beddari avatar connortroy avatar dependabot[bot] avatar lukecarrier avatar snyk-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

mkdocs-drawio-exporter's Issues

Is it possible to use non standard shape libraries?

Using the exporter works fine. But the exports don't display Icons / Shapes that are coming from non-standard shape libraries.

When drawing my diagram I added them with "+ More Shapes" and then selecting - in my case - the Azure shapes.

Screenshot 2023-02-01 at 13 17 42

`SyntaxError: f-string: unmatched '['` with 0.9.0 release

We're seeing this in a build with mkdocs-drawio-exporter 0.9.0 which wasn't an issue before:

Traceback (most recent call last):

  File "/home/travis/virtualenv/python3.9.18/bin/mkdocs", line 8, in <module>

    sys.exit(cli())

  File "/home/travis/virtualenv/python3.9.18/lib/python3.9/site-packages/click/core.py", line 829, in __call__

    return self.main(*args, **kwargs)

  File "/home/travis/virtualenv/python3.9.18/lib/python3.9/site-packages/click/core.py", line 782, in main

    rv = self.invoke(ctx)

  File "/home/travis/virtualenv/python3.9.18/lib/python3.9/site-packages/click/core.py", line 1259, in invoke

    return _process_result(sub_ctx.command.invoke(sub_ctx))

  File "/home/travis/virtualenv/python3.9.18/lib/python3.9/site-packages/click/core.py", line 1066, in invoke

    return ctx.invoke(self.callback, **ctx.params)

  File "/home/travis/virtualenv/python3.9.18/lib/python3.9/site-packages/click/core.py", line 610, in invoke

    return callback(*args, **kwargs)

  File "/home/travis/virtualenv/python3.9.18/lib/python3.9/site-packages/mkdocs/__main__.py", line 283, in build_command

    cfg = config.load_config(**kwargs)

  File "/home/travis/virtualenv/python3.9.18/lib/python3.9/site-packages/mkdocs/config/base.py", line 378, in load_config

    errors, warnings = cfg.validate()

  File "/home/travis/virtualenv/python3.9.18/lib/python3.9/site-packages/mkdocs/config/base.py", line 230, in validate

    run_failed, run_warnings = self._validate()

  File "/home/travis/virtualenv/python3.9.18/lib/python3.9/site-packages/mkdocs/config/base.py", line 188, in _validate

    self[key] = config_option.validate(value)

  File "/home/travis/virtualenv/python3.9.18/lib/python3.9/site-packages/mkdocs/config/config_options.py", line 182, in validate

    return self.run_validation(value)

  File "/home/travis/virtualenv/python3.9.18/lib/python3.9/site-packages/mkdocs/config/config_options.py", line 1064, in run_validation

    self.load_plugin_with_namespace(name, cfg)

  File "/home/travis/virtualenv/python3.9.18/lib/python3.9/site-packages/mkdocs/config/config_options.py", line 1102, in load_plugin_with_namespace

    return (name, self.load_plugin(name, config))

  File "/home/travis/virtualenv/python3.9.18/lib/python3.9/site-packages/mkdocs/config/config_options.py", line 1120, in load_plugin

    plugin_cls = self.installed_plugins[name].load()

  File "/home/travis/virtualenv/python3.9.18/lib/python3.9/site-packages/importlib_metadata/__init__.py", line 184, in load

    module = import_module(match.group('module'))

  File "/opt/python/3.9.18/lib/python3.9/importlib/__init__.py", line 127, in import_module

    return _bootstrap._gcd_import(name[level:], package, level)

  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import

  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load

  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked

  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked

  File "<frozen importlib._bootstrap_external>", line 850, in exec_module

  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed

  File "/home/travis/virtualenv/python3.9.18/lib/python3.9/site-packages/mkdocs_drawio_exporter/__init__.py", line 1, in <module>

    from .exporter import DrawIoExporter, Source

  File "/home/travis/virtualenv/python3.9.18/lib/python3.9/site-packages/mkdocs_drawio_exporter/exporter.py", line 271

    img_src = f"{filename}-{page_index}.{config["format"]}"

                                                 ^

SyntaxError: f-string: unmatched '['

I'm not sure if the part of the 0.9.0 changelog which says Fix handling of diagram filenames containing spaces could be causing problems here, but none of the *.drawio files in our docs tree have spaces in the names.

This is the plugin config in our mkdocs.yaml file:

    - drawio-exporter:
        embed_format: '<object type="image/svg+xml" data="{img_src}"></object>'

These are the installed packages in the environment:

GitPython-3.1.43 babel-2.14.0 charset-normalizer-3.3.2 click-8.1.7 colorama-0.4.6 ghp-import-2.1.0 gitdb-4.0.11 idna-3.7 importlib-metadata-7.1.0 jinja2-3.1.3 livereload-2.6.3 markdown-3.6 markupsafe-2.1.5 mergedeep-1.3.4 mkdocs-1.5.3 mkdocs-drawio-exporter-0.9.0 mkdocs-git-revision-date-localized-plugin-1.2.4 mkdocs-literate-nav-0.6.1 mkdocs-macros-plugin-1.0.5 mkdocs-material-9.5.18 mkdocs-material-extensions-1.3.1 mkdocs-redirects-1.2.1 paginate-0.5.6 pathspec-0.12.1 plantuml-markdown-3.9.4 pygments-2.17.2 pymdown-extensions-10.8 python-dateutil-2.9.0.post0 pytz-2024.1 pyyaml-6.0.1 pyyaml-env-tag-0.1 regex-2024.4.16 requests-2.31.0 six-1.16.0 smmap-5.0.1 termcolor-2.4.0 tornado-6.4 urllib3-2.2.1 watchdog-4.0.0 zipp-3.18.1

`warn` => `warning`

Added a fair bit of noise to #42, doesn’t help folks unfamiliar with the stack troubleshoot problems.

Declare the plugin breaks mkdocs

Hi!

I think the plugin is not working with mkdocs 1.1

If I declare the plugin, "mkdocs serve" don't start, and I get this error:

File "/Users/jma/.asdf/installs/python/3.7.6/lib/python3.7/site-packages/mkdocsdrawioexporter/init.py", line 2, in
from .plugin import DrawIoExporterPlugin
File "/Users/jma/.asdf/installs/python/3.7.6/lib/python3.7/site-packages/mkdocsdrawioexporter/plugin.py", line 9, in
from mkdocs.utils import copy_file, string_types
ImportError: cannot import name 'string_types' from 'mkdocs.utils' (/Users/jma/.asdf/installs/python/3.7.6/lib/python3.7/site-packages/mkdocs/utils/init.py)Is this plugin because if I remove it, mkdocs serve starts wihout problem.

Thanks

Draw.io is now Diagrams.net

It looks like Jgraph are currently in the process of rebranding the Draw.io product as Diagrams.net. Hopefully this doesn't indicate that they're planning to change their monetisation strategy in a way that breaks our use case.

I think we ought to:

  • Check that it's just a name change
  • Update our docs with the new name and note the name change to reduce confusion
  • Look for Diagrams.net variants of the Draw.io binaries?

Drawio source duplicated in build directory

Hi, when I run mkdocs build, in the site directory I found the drawio source file as well the svg version. Can I disable the copy of the drawio source?

My mkdocs.yml is minimal and consist of:

site_name: My Docs
plugins:
  - drawio-exporter

Can't parse filenames with spaces

My project contains .drawio filenames like "WRK_183_016 Integration Design SIT ServiceMesh.drawio" but the exporter throws an error that it can't find the files. If I then change the filenames to "Integration_Design_SIT_ServiceMesh.drawio" it does work. And also "WRK_183_016%20Integration%20Design%20SIT%20ServiceMesh.drawio" doesn't parse. So I think it doesn't parse spaces.

Redesign the caching to be 'static assets' somehow?

I'm thinking the cache approach is somewhat non-optimal for my workflow. What about a design where the caching is somehow implemented "in-place"?

As an example, I have these files

technical/network (master)$ ls -la site_design.*
-rw-r--r--. 1 beddari beddari 13085 Mar  6 11:07 site_design.drawio
-rw-rw-r--. 1 beddari beddari  1492 Feb 26 12:53 site_design.md

but instead of writing the build outputs to the cache dir, write it directly to the same dir as above, so that I get perhaps (multipage example):

technical/network (master %)$ ls -la site_design*
-rw-r--r--. 1 beddari beddari 35832 Mar  6 11:22 site_design-0.svg
-rw-r--r--. 1 beddari beddari 33467 Mar  6 11:22 site_design-1.svg
-rw-r--r--. 1 beddari beddari  6542 Mar  6 11:22 site_design-2.svg
-rw-r--r--. 1 beddari beddari 13085 Mar  6 11:07 site_design.drawio
-rw-rw-r--. 1 beddari beddari  1492 Feb 26 12:53 site_design.md

Is this something you'd like to consider - or just not interesting? I'm aware I could just wrap this completely on the outside and forgo the markup althogether (just ref the svgs) but I think an integrated approach still has value.

Not able to find draw.io.exe

I just installed with the latest version on pip
And I have installed the latest desktop version of draw.io(diagrams.net) and also tried the no-install version.
However, when I configured the path in both ways, they just didn't work and kept telling me:

Message: 'Configured Draw.io executable "{}" doesn\'t exist'
Arguments: ('D:\\Program_Files\\draw.io',)

Although, I do have my mkdocs.yml as below:

plugins:
    - search
    - mermaid2
    - drawio-exporter:
        drawio_executable: 'D:\Program_Files\draw.io\draw.io.exe'

And the full path of the error messages are as follow:

--- Logging error ---
Traceback (most recent call last):
  File "d:\program_files\anaconda3\lib\logging\__init__.py", line 1034, in emit
    msg = self.format(record)
  File "d:\program_files\anaconda3\lib\logging\__init__.py", line 880, in format
    return fmt.format(record)
  File "d:\program_files\anaconda3\lib\logging\__init__.py", line 619, in format
    record.message = record.getMessage()
  File "d:\program_files\anaconda3\lib\logging\__init__.py", line 380, in getMessage
    msg = msg % self.args
TypeError: not all arguments converted during string formatting
Call stack:
  File "d:\program_files\anaconda3\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "d:\program_files\anaconda3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:\Program_Files\Anaconda3\Scripts\mkdocs.exe\__main__.py", line 9, in <module>
    sys.exit(cli())
  File "d:\program_files\anaconda3\lib\site-packages\click\core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "d:\program_files\anaconda3\lib\site-packages\click\core.py", line 717, in main
    rv = self.invoke(ctx)
  File "d:\program_files\anaconda3\lib\site-packages\click\core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "d:\program_files\anaconda3\lib\site-packages\click\core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "d:\program_files\anaconda3\lib\site-packages\click\core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "d:\program_files\anaconda3\lib\site-packages\mkdocs\__main__.py", line 136, in serve_command
    **kwargs
  File "d:\program_files\anaconda3\lib\site-packages\mkdocs\commands\serve.py", line 146, in serve
    _livereload(host, port, config, builder, site_dir)
  File "d:\program_files\anaconda3\lib\site-packages\mkdocs\commands\serve.py", line 78, in _livereload
    server.serve(root=site_dir, host=host, port=port, restart_delay=0)
  File "d:\program_files\anaconda3\lib\site-packages\livereload\server.py", line 356, in serve
    IOLoop.instance().start()
  File "d:\program_files\anaconda3\lib\site-packages\tornado\platform\asyncio.py", line 148, in start
    self.asyncio_loop.run_forever()
  File "d:\program_files\anaconda3\lib\asyncio\base_events.py", line 539, in run_forever
    self._run_once()
  File "d:\program_files\anaconda3\lib\asyncio\base_events.py", line 1775, in _run_once
    handle._run()
  File "d:\program_files\anaconda3\lib\asyncio\events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "d:\program_files\anaconda3\lib\site-packages\tornado\ioloop.py", line 743, in _run_callback
    ret = callback()
  File "d:\program_files\anaconda3\lib\site-packages\tornado\ioloop.py", line 907, in _run
    return self.callback()
  File "d:\program_files\anaconda3\lib\site-packages\livereload\handlers.py", line 69, in poll_tasks
    filepath, delay = cls.watcher.examine()
  File "d:\program_files\anaconda3\lib\site-packages\livereload\watcher.py", line 119, in examine
    func()
  File "d:\program_files\anaconda3\lib\site-packages\mkdocs\commands\serve.py", line 136, in builder
    build(config, live_server=live_server, dirty=dirty)
  File "d:\program_files\anaconda3\lib\site-packages\mkdocs\commands\build.py", line 236, in build
    config = config['plugins'].run_event('config', config)
  File "d:\program_files\anaconda3\lib\site-packages\mkdocs\plugins.py", line 94, in run_event
    result = method(item, **kwargs)
  File "d:\program_files\anaconda3\lib\site-packages\mkdocsdrawioexporter\plugin.py", line 45, in on_config
    self.exporter.drawio_executable_paths(sys.platform))
  File "d:\program_files\anaconda3\lib\site-packages\mkdocsdrawioexporter\exporter.py", line 135, in prepare_drawio_executable   
    self.log.error('Configured Draw.io executable "{}" doesn\'t exist', executable)
Message: 'Configured Draw.io executable "{}" doesn\'t exist'
Arguments: ('D:\\Program_Files\\draw.io',)

Fix handling of missing draw.io binary on PATH

This isn't a great look -- we need to handle the case that drawio_executable is None:

ERROR   -  Subprocess raised exception 
Traceback (most recent call last):
  File "/Users/lukecarrier/Code/AVADO/Infrastructure/Alp/Docs/venv/lib/python3.7/site-packages/mkdocsdrawioexporter/mkdocsdrawioexporter.py", line 83, in on_post_build
    exit_status = subprocess.call(cmd)
  File "/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 323, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 775, in __init__
    restore_signals, start_new_session)
  File "/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 1436, in _execute_child
    executable = os.fsencode(executable)
  File "/usr/local/bin/../Cellar/python/3.7.4_1/bin/../Frameworks/Python.framework/Versions/3.7/lib/python3.7/os.py", line 809, in fsencode
    filename = fspath(filename)  # Does type-checking of `filename`.
TypeError: expected str, bytes or os.PathLike object, not NoneType

Multi-page document support, quick start docs

When running a mkdocs build or mkdocs serve command the following error occurs.

Traceback (most recent call last):
  File "/Users/darthveitcher/.local/share/virtualenvs/myproject-LFrY1FU6/lib/python3.7/site-packages/mkdocsdrawioexporter/mkdocsdrawioexporter.py", line 86, in on_post_build
    mkdocs.utils.copy_file(cache_filename, abs_dest_path)
  File "/Users/darthveitcher/.local/share/virtualenvs/myproject-LFrY1FU6/lib/python3.7/site-packages/mkdocs/utils/__init__.py", line 120, in copy_file
    shutil.copyfile(source_path, output_path)
  File "/Users/darthveitcher/.local/share/virtualenvs/myproject-LFrY1FU6/lib/python3.7/shutil.py", line 120, in copyfile
    with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/darthveitcher/wip/myproject/docs_src/drawio-exporter/b67cd0c521ac80ff54e5d104542206f8aab93e64'

It seems to be expecting a file here (I'm assuming some kind of generated output) as manually creating a directory here generates an [Errno 21] Is a directory.

Possibly a symptom of needing a more detailed Quick start set of instructions?

Errors when using plugin in Github Actions

I am trying to implement the plugin as part of a github action that builds a mkdocs site to github pages.

The steps in the action install all the components but for some reason when it gets to the step of actually deploying the site it errors out.

Error:

mkdir: cannot create directory ‘/run/user/1001’: Permission denied 
ERROR  -  Export failed with exit status 1; skipping copy

Action:

name: gh page ci 
on: [pull_request]
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-python@v2
        with:
          python-version: 3.x

      - run: pip install \
              mkdocs-material \
              mkdocs-drawio-exporter \

      - run: sudo apt-get update
      - run: sudo snap install drawio
      - run: mkdocs gh-deploy --force

Any thoughts on how to fix this?

Deprecation warning when converting Draw.io images to svgs

I get the following deprecation warning when building a Mkdocs website that contains draw.io images.

(electron) The default value of app.allowRendererProcessReuse is deprecated, it is currently "false".  It will change to be "true" in Electron 9.  For more information please check https://github.com/electron/electron/issues/18397
(node:58589) DeprecationWarning: Passing functions, DOM objects and other non-cloneable JavaScript objects to IPC methods is deprecated and will throw an exception beginning with Electron 9.
(node:58589) DeprecationWarning: Passing functions, DOM objects and other non-cloneable JavaScript objects to IPC methods is deprecated and will throw an exception beginning with Electron 9.

For every Draw.io image the above message is printed.

I'm using a Mac that has Draw.io 13.0.3 installed using Homebrew Cask.

My drawio-exporter config:

    - drawio-exporter:
          cache_dir: 'rendered-diagrams'
          format: svg
          sources: '*.drawio'

Github Actions

Hello everyone if you are here with some kind of difficult to use and make it work here is the github actions file working perfect well.

name: ci 
on:
  push:
    branches:
      - main
    paths-ignore:
      - "README.md"
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-python@v2
        with:
          python-version: 3.x
      - run: sudo apt-get install -y libasound2 xvfb
      - run: pip install mkdocs-material 
      - run: pip install mkdocs-drawio-exporter
      - name: Install drawio
        run: |
          wget https://github.com/jgraph/drawio-desktop/releases/download/v18.1.3/drawio-amd64-18.1.3.deb
          sudo dpkg -i drawio-amd64-18.1.3.deb
      - run: xvfb-run -a mkdocs gh-deploy --force

Thanks @LukeCarrier for yout extension/plugin

Draw.io CLI discovery

Locate the Draw.io executable in the default installation locations if PATH-based lookup fails and no path is specified in the configuration file.

  • Linux
    • /opt/draw.io/drawio
  • macOS
    • /Users/:user/Applications/draw.io.app/Contents/MacOS/draw.io
    • /Applications/draw.io.app/Contents/MacOS/draw.io
  • Windows
    • C:\Program Files\draw.io\draw.io.exe
    • C:\Program Files (x86)\draw.io\draw.io.exe

Alt-Text from draw.io document text

Feature consideration/request:
Parse the draw.io document for all text, then embed that text as the alt text of the image so that searches/search engines can parse it and make image contents searchable.

Using an <object> tag in created svg

We are using your plugin within mkdocs pages with svg format. We found out, we cannot use interactivity within svg(hyperlinks) if <img> tag is used.

Is it possible instead of <img> tag to use <object> tag?

We tested it as following and hyperlinks from svg works only in object
<object type="image/svg+xml" data="image.svg"></object>

Split out plugin and exporter into separate modules, start testing

I've been putting off unit testing this code because I've been struggling to isolate the MkDocs plugin from the rest of the code.

I think the best compromise would be to move the logic out of the plugin class and keep only the configuration schema and the handlers for MkDocs plugin events there. We could then leave this code untested, but test the logic.

Empty document crashes build

Hi, this might be per design currently, but referring to an empty tab in a multipage document causes a crash

Error: Export failed: /docs/content/technical/network/site_design.drawio
ERROR   -  Output file not created in cache 
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/mkdocsdrawioexporter/plugin.py", line 85, in on_post_build
    copy_file(cache_filename, abs_dest_path)
  File "/usr/local/lib/python3.7/site-packages/mkdocs/utils/__init__.py", line 100, in copy_file
    shutil.copyfile(source_path, output_path)
  File "/usr/lib64/python3.7/shutil.py", line 120, in copyfile
    with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: '/docs/content/cache/9a7d5d6802558d95399cdc2f0d36a830a92be749-3'

As a workaround I could just put some object in the tab but ... I think as a user I'd expect an empty tab to just produce empty output, somehow?

Not possible to run within Docker

There are a couple of problems here:

  • Because draw.io is a desktop application built atop Electron, it requires a running X server to draw a window, even if it's just opening to perform a CLI export. Whilst there's some talk (jgraph/drawio-desktop#127) of a headless option, it doesn't have feature parity with the desktop app. In headless scenarios it must be used in conjunction with Xvfb or its simpler wrapper xvfb-run.
  • Chrome's sandboxing means we need to be able to pass the --no-sandbox option or create an additional user in which to run the service.

I think we should:

  • Document the additional dependencies and use of xvfb-run to get the plugin working in headless configurations.
  • #14 Add a drawio_args plugin setting that allows adding additional options to the end of the command. Note that my testing discovered an argument parsing bug in the CLI that causes option values to jump around if options that don't expect arguments are provided ahead of options that do expect them.

Consider implementing headless exports to remove Electron dependency

We're currently using the Draw.io desktop application to perform exports. This Electron application also exposes a CLI that allows us to export specific pages to a range of formats.

Whilst the Electron app is an ideal target for installation on desktops, it's less ideal in headless setups as it requires a running display server in order to do anything, even when we don't want a window.

Some bugs on this:

JGraph have a server-side implementation of exports used in browsers that aren't capable of doing the export locally, which uses Puppeteer. I'm thinking that we should write a client for this and have users run it in an additional container.

  • Confirm jgraph/draw-image-export2 supports all of the same formats as the Desktop app:
    • pdf
    • png
    • jpg
    • svg
    • vsdx
  • Containerise jgraph/draw-image-export2
  • Add an export_mode option with both drawio and export2 modes
  • Add an export2_uri option to specify the service's address
  • Write the code

Does not work github pages

Continues processing but does not generate the output svg, displays the message below in the log.

ERROR    -  Export failed with exit status -6; skipping copy
The futex facility returned an unexpected error code.

image

ci.yml

name: ci 
on:
  push:
    branches: 
      - main
jobs:
  deploy:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        drawio-version: [14.5.1]
        python-version: [3.9]
        drawio-arch: [amd64]
        drawio-sha256sum: [0cabdf1e9a051fc38672a9233b1b2d5368d2a776fe3d3f5e09a823278b899976]
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-python@v2
        with:
          python-version: 3.x
      - name: Install Draw.io Desktop
        run: |
            set -euo pipefail
            drawio_deb="drawio-${{ matrix.drawio-arch }}-${{ matrix.drawio-version }}.deb"
            drawio_url="https://github.com/jgraph/drawio-desktop/releases/download/v${{ matrix.drawio-version }}/drawio-${{ matrix.drawio-arch }}-${{ matrix.drawio-version }}.deb"
            curl -L -o "$drawio_deb" "$drawio_url"
            sha256sum --check <<<"${{ matrix.drawio-sha256sum }}  $drawio_deb"
            sudo apt-get install -y libasound2 xvfb ./"$drawio_deb"
      - run: pip install mkdocs-drawio-exporter
      - run: pip install mkdocs-minify-plugin
      - run: mkdocs gh-deploy --force

Any suggestions on how to solve?

No Output file

Hi,

I cannot export some of my drawio "WARNING - Export successful, but wrote no output file".

[801:1214/171259.472280:ERROR:viz_main_impl.cc(186)] Exiting GPU process due to errors during initialization
[837:1214/171259.504245:ERROR:gpu_memory_buffer_support_x11.cc(44)] dri3 extension not supported.
[811:1214/171259.507686:ERROR:command_buffer_proxy_impl.cc(128)] ContextResult::kTransientFailure: Failed to send GpuControl.CreateCommandBuffer.
[779:1214/171303.594175:ERROR:validation_errors.cc(117)] Invalid message: VALIDATION_ERROR_DESERIALIZATION_FAILED
[779:1214/171303.594354:ERROR:interface_endpoint_client.cc(687)] Message 887036082 rejected by interface viz.mojom.CopyOutputResultSender
[779:1214/171303.594505:ERROR:browser_child_process_host_impl.cc(752)] Terminating child process for bad message: Received bad user message: Validation failed for viz.mojom.CopyOutputResultSender.0 [VALIDATION_ERROR_DESERIALIZATION_FAILED]
Error: Export failed: /builds/aws/documentation/mkdocs/docs/map2/imgs/Global_Architecture.drawio
[779:1214/171303.619743:ERROR:gpu_process_host.cc(966)] GPU process exited unexpectedly: exit_code=15
[853:0100/000000.677559:ERROR:connection.cc(46)] X connection error received.
INFO - DeprecationWarning: The 'warn' method is deprecated, use 'warning' instead
File "/usr/local/lib/python3.11/site-packages/mkdocsdrawioexporter/plugin.py", line 94, in on_post_build
log.warn('Export successful, but wrote no output file')
File "/usr/lib64/python3.11/logging/init.py", line 1504, in warn
warnings.warn("The 'warn' method is deprecated, "
WARNING - Export successful, but wrote no output file

Do you have any clue.

Consider some form of static analysis in CI

Following #59 we ought to extend our integration checks to cover oversights:

…/mkdocs-drawio-exporter on  HEAD (157dd90) is 📦 v0.9.0 via 🐍 v3.12.2
at 22:53:02 ✖ 1 🐠 ❯ asdf shell python 3.8.19

…/mkdocs-drawio-exporter on  main [⇣1] is 📦 v0.9.0 via 🐍 v3.8.19 took 3s 
at 22:53:12 🐠 ❯ g sw --detach v0.9.0
HEAD is now at 157dd90 Bump version to v0.9.0

…/mkdocs-drawio-exporter on  HEAD (157dd90) is 📦 v0.9.0 via 🐍 v3.8.19 
at 22:53:17 🐠 ❯ python -m flake8 mkdocs_drawio_exporter/
mkdocs_drawio_exporter/__init__.py:1:1: F401 '.exporter.DrawIoExporter' imported but unused
mkdocs_drawio_exporter/__init__.py:1:1: F401 '.exporter.Source' imported but unused
mkdocs_drawio_exporter/__init__.py:2:1: F401 '.plugin.DrawIoExporterPlugin' imported but unused
mkdocs_drawio_exporter/exporter.py:271:62: E999 SyntaxError: invalid syntax
mkdocs_drawio_exporter/plugin.py:52:61: E999 SyntaxError: invalid syntax
mkdocs_drawio_exporter/tests/__init__.py:1:1: F401 '.exporter.ExporterTests' imported but unused
mkdocs_drawio_exporter/tests/exporter.py:82:80: E501 line too long (95 > 79 characters)
mkdocs_drawio_exporter/tests/exporter.py:108:80: E501 line too long (87 > 79 characters)
mkdocs_drawio_exporter/tests/exporter.py:129:80: E501 line too long (109 > 79 characters)
mkdocs_drawio_exporter/tests/exporter.py:134:80: E501 line too long (96 > 79 characters)
mkdocs_drawio_exporter/tests/exporter.py:141:80: E501 line too long (82 > 79 characters)
mkdocs_drawio_exporter/tests/exporter.py:144:80: E501 line too long (90 > 79 characters)
mkdocs_drawio_exporter/tests/exporter.py:161:80: E501 line too long (113 > 79 characters)
mkdocs_drawio_exporter/tests/exporter.py:191:28: E711 comparison to None should be 'if cond is None:'
mkdocs_drawio_exporter/tests/exporter.py:207:80: E501 line too long (113 > 79 characters)
mkdocs_drawio_exporter/tests/exporter.py:219:28: E711 comparison to None should be 'if cond is None:'
mkdocs_drawio_exporter/tests/exporter.py:236:80: E501 line too long (113 > 79 characters)
mkdocs_drawio_exporter/tests/exporter.py:269:80: E501 line too long (108 > 79 characters)
mkdocs_drawio_exporter/tests/exporter.py:286:23: E712 comparison to False should be 'if cond is False:' or 'if not cond:'
mkdocs_drawio_exporter/tests/exporter.py:325:23: E711 comparison to None should be 'if cond is None:

Error while exporting image

My application running on a kubernetes linux cluster is receiving an error while trying to export the image.

Exporting "/tmp/docs_83a7vd53/test.drawio" to "/tmp/backstage-aBt9dA/docs/drawio-exporter/71d93ea61644eca01ccdd1a939d9fb2af53a382d-0"
Using export command ['/usr/bin/drawio', '--export', '/tmp/docs_83a7vd53/test.drawio', '--page-index', '0', '--output', '/tmp/backstage-aBt9dA/docs/drawio-exporter/71d93ea61644eca01ccdd1a939d9fb2af53a382d-0', '--format', 'png', '--no-sandbox']
[24:0902/142640.911050:ERROR:ozone_platform_x11.cc(247)] Missing X server or $DISPLAY
[24:0902/142640.911122:ERROR:env.cc(226)] The platform failed to initialize.  Exiting.
The futex facility returned an unexpected error code.
Export failed with exit status -6; skipping copy

I have set a DISPLAY env_var with 99 as value.

My mkdocs plugin is configured just with format property.

- drawio-exporter:
      format: png

In my docker image, we add the following instructions:

RUN apt-get install -y graphviz plantuml libasound2 xvfb wget

# draw.io dependencies
RUN apt-get install -y libsecret-1-0 libnotify4 libxss1 xdg-utils libgbm-dev

RUN pip3 install slugify
RUN pip3 install mkdocs-kroki-plugin
RUN pip3 install mkdocs-drawio-exporter
RUN pip3 install mkdocs-techdocs-core

RUN wget https://github.com/jgraph/drawio-desktop/releases/download/v20.2.3/drawio-amd64-20.2.3.deb
RUN dpkg -i drawio-amd64-20.2.3.deb

Any idea on what is happening?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.