Closed usmcamp0811 closed 2 years ago
Adding examples, and getting back to/updating this package, has been on my to-do list for a really long time. If you can give me some insight into the context you'd like to use it in that'd be very helpful. I can then prioritize writing something targeted towards that. Some examples:
An immediate answer to the use case you already provided would be something along the lines of
(@v1.7) pkg> activate --temp
Activating new project at `/tmp/jl_iZZPQ8`
julia> using Kroki
│ Package Kroki not found, but a package named Kroki is available from a registry.
│ Install package?
│ (jl_iZZPQ8) pkg> add Kroki
└ (y/n) [y]: y
...
julia> diagram = plantuml"""
@usmcamp0811 -> @bauglir: Can I output this to SVG?
@bauglir -> @usmcamp0811: Yes you can!
"""
┌────────────┐ ┌────────┐
│@usmcamp0811│ │@bauglir│
└─────┬──────┘ └───┬────┘
│ Can I output this to SVG?│
│ ─────────────────────────>
│ │
│ Yes you can! │
│ <─────────────────────────
┌─────┴──────┐ ┌───┴────┐
│@usmcamp0811│ │@bauglir│
└────────────┘ └────────┘
julia> write("diagram.svg", Kroki.render(diagram, "svg"))
# Edit: this was what I wrote initially, but it's easier to just call `render`
julia> write("diagram.svg", sprint(show, MIME"image/svg+xml"(), diagram))
This will render the diagram (initially to the REPL) and then write it out to a diagram.svg
file in your current working directory:
In this case, I used a PlantUML diagram but you can use any of the tools listed here. The string macro names are listed here (just leave off the @
and the _str
and append a string to what's left.
Note that you will not always have to explicitly write out to a file. If you're in the context of Pluto.jl or Documenter.jl, diagrams should automatically as, typically, SVG.
Not sure why I didn't think about Kroki.render
, which will probably be export
ed in an upcoming version, but that's a lot easier than the sprint
approach... I've updated the example above.
A, more or less accurate, overview of acceptable output formats is available on Kroki's website.
I just stumbled on this and Kroki and it sounds neat! But I. Having a hard time getting anything working. Can I get a working example of how to make a diagram and output an svg?
Thanks