asciidoctor / asciidoctor-kroki

Asciidoctor.js extension to convert diagrams to images using Kroki!
https://kroki.io/
MIT License
147 stars 50 forks source link

Be able to import text into a fenced block from somewhere else #279

Closed chtenb closed 3 years ago

chtenb commented 3 years ago

For some diagram types it it possible to define macros and variables. Unless I missed something that currently needs to be replicated in each diagram, which is a maintenance horror. If they could be put somewhere else and imported from there through an attribute on the fenced block or something, that would be really powerful.

It doesn't matter to me personally whether those macros were to be defined in an external text file or somewhere else in the asciidocument.

ggrossetie commented 3 years ago

For some diagram types it it possible to define macros and variables.

I'm not sure I fully understand. Are you referring to the block and block macro syntax?

Block syntax

[plantuml]
....
Bob -> Alice : Bonjour!
....

_Block macro syntax__

plantuml::hello.puml[]

If so, both are automatically declared when the extension is registered: https://github.com/Mogztter/asciidoctor-kroki/blob/c66ab7479c62511741f379956c8b5e0216f879e8/src/asciidoctor-kroki.js#L196-L239

chtenb commented 3 years ago

I'm not sure I fully understand. Are you referring to the block and block macro syntax?

Sorry, I should have been more clear. I'm referring to variable/macro constructions as supplied by the respective diagram languages. Here is an example. In Pikchr you can define macros like

define onSuccess {
  S0: arrow color lightblue
  B: box $1 fit
  SF: arrow right linerad then down then right color orange behind B
  S1: arrow from SF.start right until even with SF.end color lightblue behind B
  move from S0.start down lineht
  F: arrow right until even with SF.end color orange
  move up lineht; right
}

which can then be used like

onSuccess("hello")

I've got four of those macros and I've got 20 or so pikchr diagrams in my asciidoc document. Currently I'm duplicating these macros in each one of them, so I can use them to write my diagrams. But this makes my document quite unreadable and unmaintainable, so I'm sure there must be a better way.

ggrossetie commented 3 years ago

I see, so you want to share Pikchr variables/macros between diagrams, is that correct? You can probably leverage AsciiDoc include directive:

on-success-macro.pikchr

define onSuccess {
  S0: arrow color lightblue
  B: box $1 fit
  SF: arrow right linerad then down then right color orange behind B
  S1: arrow from SF.start right until even with SF.end color lightblue behind B
  move from S0.start down lineht
  F: arrow right until even with SF.end color orange
  move up lineht; right
}

doc.adoc

[pikchr]
....
include::on-success-macro.pikchr[]

onSuccess("hello")
....

[pikchr]
....
include::on-success-macro.pikchr[]

onSuccess("bye")
....

Does this help?

chtenb commented 3 years ago

That's exactly what I meant. I didn't know you could do that in a fenced block. Thanks!