mikitex70 / redmine_drawio

Macro plugin to embed draw.io diagrams into Redmine wiki pages
MIT License
125 stars 51 forks source link

SVG as format for drawio_attach and drawio_dmsf macroses #17

Closed dinya closed 7 years ago

dinya commented 7 years ago

Very thanks for the great tool!

Is it possible to add option to drawio_attach and drawio_dmsf macroses to save image as SVG?

It will be useful to copy text from diagram or for adding URL to nodes.

mikitex70 commented 7 years ago

Sorry but they work only with the PNG format, which is the only format that supports saving the source diagram embedded with the image. It is a "limitation" of the draw.io editor. Maybe I can do a workaround, a "double save" of the diagram in source and SVG format and then inject the source into the SVG so to be able to extract it again when an edit is required. Stay tuned, I will try this weekend.

mikitex70 commented 7 years ago

I've found that the draw.io editor supports saving in SVG with and embedded diagram source, so I'm happy to release this new version. Add add .svg extension diagram names and you are free to edit diagrams in SVG format.

dinya commented 7 years ago

Add add .svg extension diagram names and you are free to edit diagrams in SVG format.

I tried

{{drawio_dmsf(diagrams/test.svg)}}

and got Error 500 after page reload

Started GET "/projects/project1/wiki/Test" for 192.168.0.3 at 2017-04-12 08:15:27 +0500
Processing by WikiController#show as HTML
  Parameters: {"project_id"=>"project1", "id"=>"Test"}
  Current user: USER (id=5)
  Rendered wiki/_content.html.erb (45.1ms)
  Rendered wiki/show.html.erb within layouts/base (69.5ms)
Completed 500 Internal Server Error in 223ms (ActiveRecord: 32.9ms)

ActionView::Template::Error (incompatible character encodings: UTF-8 and ASCII-8BIT):
    44:     <hr />
    45: <% end %>
    46:
    47: <%= render(:partial => "wiki/content", :locals => {:content => @content}) %>
    48:
    49: <%= link_to_attachments @page %>
    50:
  app/views/wiki/show.html.erb:47:in `_app_views_wiki_show_html_erb__4095262023663339092_43080820'
  plugins/redmine_wiki_extensions/lib/wiki_extensions_wiki_controller_patch.rb:51:in `render_with_wiki_extensions'
  plugins/redmine_wiki_extensions/lib/wiki_extensions_wiki_controller_patch.rb:62:in `respond_to_with_wiki_extensions'
  app/controllers/wiki_controller.rb:116:in `show'
  lib/redmine/sudo_mode.rb:63:in `sudo_mode'

But {{drawio_dmsf(diagrams/test)}} and {{drawio_dmsf(diagrams/test.png)}} works well and saves diagram as diagrams/test.png.

BTW, {{drawio_dmsf(diagrams/test.SVG)}} saves as diagrams/test.SVG but with PNG content. I don't know if it matters for Windows users.

mikitex70 commented 7 years ago

The extension must be in lowercase to be recognized as svg; I will add code to check the extension in a case-insensitive manner. Your error seems to be cause by an incorrect UTF-8 character, maybe I've use some character with a wrong encoding, I will recheck this afternoom. What's your platform, Windows? What Redmine installation you use, Bitnami, Docker, virtual machine or custom installation?

dinya commented 7 years ago

I use custom installation of Redmine 3.3.1 with phusion passenger under Ubuntu 14.04.5. Locale is UTF-8

mikitex70 commented 7 years ago

I cannot reproduce your error; what plugins are you using? The backtrace seems reporting a problem with the redmine_wiki_extensions plugin, but it seems strange to me. Can you try to disable/remove the other plugins so to isolate where is the error?

dinya commented 7 years ago

@mikitex70,

I updated DMSF to 1.5.9-master (and other used plugins to fresh versions) and SVG output is working now.

But math doesn't not work correctly: `\sin^2 x` is not rendered as math and is `\sin^2 x` still. But it's rendered well in draw.io editor.

{{mj (\sin^2 x) }} (redmine_latex_mathjax plugin) doesn't working too.

mikitex70 commented 7 years ago

Have you tried to export the diagram in SVG format directly from the editor and open it directly with a browser? Maybe the SVG format can't handle math without additional libriaries. I' will search if it needs to include something, maybe a Javascript library.

dinya commented 7 years ago

@mikitex70

Have you tried to export the diagram in SVG format directly from the editor and open it directly with a browser?

this way doesn't render LaTeX in proper way too.

mikitex70 commented 7 years ago

So the problem seems to be related to the SVG format. In the weekend I will do some test to see if using some Javascript library may overcome to the problem. But maybe a Javascript library can solve the problem only if the SVG is embedded in a web page.

mikitex70 commented 7 years ago

Try the new version from the develop branch: now it renders the math expressions in SVG diagrams. Tested with Firefox; with Chrome I've some trouble, sometimes is working and sometimes not.

dinya commented 7 years ago

Please, note that https://www.mathjax.org/cdn-shutting-down/

mikitex70 commented 7 years ago

Already noted, changed the plug-in but the sources are not yet pushed. Maybe this weekend I will release the new version.

dinya commented 7 years ago

Tested with last Chrome, Firefox, Yandex under Windows 7 64 bit.

All works fine. Cann't note any troubles.