Closed yaron-top closed 4 years ago
I’ve never tried this myself, but I think you need to set the subs attribute on blocs to get this behaviour. It will have to include macros
to get ifdef processing.
I’m not 100% sure this will work right away. This might require some code changes to the extension as well.
Hi pepijnve,
Thanks a lot for the tip.
I wrote the following asciidoc test using subs attributes:
= Test
:flag: 9
component “flag={flag}”
[subs=”attributes+”]
….
component “In block flag={flag}”
….
[plantuml, subs=”attributes+”]
….
component “In plantuml flag={flag}”
….
= Test
component “flag=9”
component “In block flag=9”
In plantuml flag=9
= Test
component “flag=9”
component “In block flag=9”
In plantuml flag={flag}
The 3rd line appear inside a UML component notation picture.
It seems that there is a problem with the plantuml block. Is there any workaround to solve this problem? If so, a small code example would be highly appreciated.
I had a quick look at the code already. Seems like it should be working already. I’ll have to do some testing to be able to tell you more. I might have some time for that this evening or tomorrow.
The preprocessor directives run before any extension touches the lines, so they should get processed no matter where they are.
The problem might be that you're writing the conditional directive as "Ifdef" instead of "ifdef". The first "i" should be lowercase. Same for the "e" in "endif".
The preprocessor directives run before any extension touches the lines, so they should get processed no matter where they are.
The problem might be that you're writing the conditional directive as "Ifdef" instead of "ifdef". The first "i" should be lowercase. Same for the "e" in "endif".
Thank you @mojavelinux, I had a typo, the proprocessor is not working using lower cases as well.
As @pepijnve suggested, I tried the subs="attributes+" and it seems like the right direction, however, the plantuml block is not affected.
Can you please refer to my new comment of testing with subs?
Regards.
subs have no affect on preprocessor directives. The preprocessor directives don't see the structure of the document at all. They are processed before the block is parsed (ahead of parsing).
If you are using attribute references in a verbatim block that are not part of a preprocessor directive (such as ifdef or include), then you do need subs. The subs affect lines as they exist after the preprocessor directives have run.
However, when the subs get applied relative to when the diagram is generated is something that is up to the extension.
@yaron-top I tested this locally and it works correctly as far as I can tell. I did have to massage the asciidoc code you provided a bit. The original contains “
and ”
instead of "
. There was already a test case covering this exact behaviour (see https://github.com/asciidoctor/asciidoctor-diagram/blob/master/spec/plantuml_spec.rb#L1000).
I am sorry for the trouble. You are right. Everything works fine. It seems that the problem was in the editor I used (AsciidocFx). Thanks a lot for your help.
In case someone wants a full working asciidoc example:
:version: stef
[source, subs="attributes+"]
----
<version>{version}</version>
----
[plantuml, subs="attributes+"]
----
@startuml
Component "version? {version}"
@enduml
----
Renders as:
Hi I’m looking for a way to incorporate an Asciidoc attribute in a plantuml section so that the attribute influences the parsing evaluation of a puml section.
When I use the Asciidoc “Ifndef::[]” statement in the Asciidoc file everyting goes fine. However when I place the Ifndef::[] statement in the puml file, the conditional is not interpreted and the plant uml gets it as is.
How can I add conditionals to plant uml based on an asccidoc attribute?
Code example to demonstrate the problem: Test.adoc content: [plantuml, target=”test1”, format=”png”] …. Ifndef::flag[] // NO PROBLEM HERE @startuml Component “This works fine” @enduml endif::[]
…. [plantuml, target=”test2”, format=”png”] …. @startuml // HERE THERE IS A PROBLEM Ifndef::flag[] Component “This yields syntax error” Endif::[] @enduml
Expected behavior: 2 diagrams of components. One with the string “This works fine”, and one with the string “This file yields syntax error” Actual behavior: One diagram appears fine and then a diagram announcing a Syntax error: [From string (line 4)] @startuml skinparam dpi 200. // HERE THERE IS A PROBLEM Ifndef::flag[] Syntax Error?
Environment: AsciidoctorJ 2.2.0 (Asciidoctor 2.0.10)