marc0l92 / joplin-plugin-plantUML

Render PlantUML diagram inside your Joplin notes.
MIT License
47 stars 8 forks source link

showing image raw data #6

Closed enboig closed 2 years ago

enboig commented 2 years ago

When introducing

@startuml
ditaa
+--------+   +-------+    +-------+
|        +---+ ditaa +--> |       |
|  Text  |   +-------+    |diagram|
|Document|   |!magic!|    |       |
|     {d}|   |       |    |       |
+---+----+   +-------+    +-------+
    :                         ^
    |       Lots of work      |
    +-------------------------+
@enduml

Image is not rendered, it show the PNG raw image in note; I took the example from https://plantuml.com/ditaa; should the code be updated?

marc0l92 commented 2 years ago

Thanks for letting me know about this issue. Unfortunately I cannot fix this issue since it is a bug in plantUML server.

We had a similar issue with math formulas and you can use the same workaround to render properly this type of diagrams:

3

In few words, you just need to change in the plugin options the rendering mode to png.

I updated the Readme of this project to include those two known issues.

enboig commented 2 years ago

Thanks for your answer. So the public server gives a different response (svg or png) depending on the input? Couldn't the plugin get the mime-type of the response to adapt? I prefer vector images when possible. Another option could be to specify rendering format for each input; maybe a

```plantuml+svg
```plantuml+png
enboig commented 2 years ago

I checked https://github.com/plantuml/plantuml/blob/master/src/net/sourceforge/plantuml/ditaa/PSystemDitaa.java and it appear it don't throw any error, it just always send back a PNG file.

marc0l92 commented 2 years ago

You are right, the output is a PNG image (example).

But the content-type is not image/png but image/svg+xml: image

If you open the link with the browser it will not work because it is trying to parse it as xml even if it is a PNG.

I need to find a way to understand what is the real type of the response since I cannot rely on the response header or the request I do.

enboig commented 2 years ago

I suppose the content-type is set depending only on the url of the call. Can you check the conten-type of the response data (not the response itself)? By the way, I don't know if joplin plugin system provides a way to pass a parameter to the plugin "per call"; so PNG or SVG could be specified for each graph.

marc0l92 commented 2 years ago

I may found a solution. I'm now checking the response body to look for magic numbers of PNG images. You will find this fix in version 1.8.0 of this plugin.

marc0l92 commented 2 years ago

do you think, the feature to select the rendering type for each diagram (plantuml+svg, plantuml+png), it is still needed?

do you see some use cases when it could be useful?

enboig commented 2 years ago

I don't think selecting rendering type for each diagram is necessary any more; I will choose SVG at plugin; and for a few cases of PNG ones the plugin is handling it.

Thanks for your job (and time!)