modelmat / sphinxcontrib-drawio

Sphinx extension for including draw.io files.
MIT License
39 stars 17 forks source link

figure properties set to Path instead of str #60

Closed lokeller closed 3 years ago

lokeller commented 3 years ago

When using this extension together with the extension sphinx-imgconvert I get an error due to the fact that at the following lines:

https://github.com/Modelmat/sphinxcontrib-drawio/blob/1dcdb8970c5a498db3cf1b4a54d52014684c3892/sphinxcontrib/drawio/__init__.py#L160-L165

the candidates and uri properties of the node are set to a Path object created in the _drawio_export function.

I'm not an expert of the docutils/sphinx codebase but I think that Docutils is setting uri for figure nodes to a string here:

https://github.com/docutils-mirror/docutils/blob/e88c5fb08d5cdfa8b4ac1020dd6f7177778d5990/docutils/parsers/rst/directives/images.py#L29

and Sphinx is setting the default candidate to a str here:

https://github.com/sphinx-doc/sphinx/blob/1285e0cabed517d4bf24b00c5fd68804a26e8a91/sphinx/environment/collectors/asset.py#L83

It seems therefore that sphinx-imgconvert is correct in expecting a string and not a Path object.

I think the extension could be adapted by casting the Path object to a str in these two locations:

https://github.com/Modelmat/sphinxcontrib-drawio/blob/1dcdb8970c5a498db3cf1b4a54d52014684c3892/sphinxcontrib/drawio/__init__.py#L206

https://github.com/Modelmat/sphinxcontrib-drawio/blob/1dcdb8970c5a498db3cf1b4a54d52014684c3892/sphinxcontrib/drawio/__init__.py#L272

modelmat commented 3 years ago

Hi

Feel free to create a PR changing this and I should be able merge it. I'm busy for the next few days but I'll get back to you then.