yuzutech / kroki

Creates diagrams from textual descriptions!
https://kroki.io
MIT License
2.78k stars 206 forks source link

Allow diagram options within the diagram definition #1314

Open unikitty37 opened 1 year ago

unikitty37 commented 1 year ago

827 adds the ability to set diagram options, but not as part of the diagram definition.

I'm using GitLab's Kroki integration, which allows me to define entries inline as part of issues or wiki pages using Markdown:

 ```rackdiag
   12U;
   1: UPS [2U];
  ```

but I cannot see how to set options like size in this — GitLab doesn't let me control the GET/POST request or HTTP headers, obviously.

As the default width for rackdiag is so narrow it causes ugly line-wrapping, I seem to be stuck with it. (It's also not clear from the documentation whether you can just set the width and let the height be determined automatically — hopefully this is the case…)

Would it be possible to support diagram options within the diagram definition, to allow for use with GitLab and similar?

ggrossetie commented 1 year ago

(...) but I cannot see how to set options like size in this — GitLab doesn't let me control the GET/POST request or HTTP headers, obviously.

It really depends on the markup language. For instance, with AsciiDoc you can define attributes on a block:

[rackdiag,size=1024]
....
   12U;
   1: UPS [2U];
....

In the above example, the size attribute can be retrieved and sent to Kroki. That's not yet implemented but we are working on it: https://github.com/Mogztter/asciidoctor-kroki/issues/334

As far as I know, this feature does not exist in Markdown.

Would it be possible to support diagram options within the diagram definition, to allow for use with GitLab and similar?

That's a good question! I thought about it and the main concern is that we have to make sure that it won't conflict with the diagram definition (and that somehow the syntax remains consistent across all diagram formats).

rackdiag allows comments when a line begins with // so we could use that:

```rackdiag
// diagram-options: size=1024, antialias=true
// output-format: png
  12U;
  1: UPS [2U];


But then again we need to study each diagram libraries to see what we can do. 
Feel free to to suggest a syntax for each diagram libraries supported by Kroki.