How to include partial with different attributes and without empty lines

79 Views Asked by At

I have the partial with name hello_world

Hello {lang} World!

I want to include the partial and change the attribute {lang}. I have manage to do it with

:lang: Java
include::partial$hello_world.adoc[]

:lang: PHP
include::partial$hello_world.adoc[]

I would like to get

Hello Java World!Hello PHP World!

But including the partial like that, i get the extra space from the empty line between the two includes.

Hello Java World!

Hello PHP World!

I have try to include the partial with

include::partial$hello_world.adoc[lang=Java]
include::partial$hello_world.adoc[lang=PHP]

But it didn't work.

Is there a way to include the partial with different attributes without the empty line?

2

There are 2 best solutions below

0
Panos Bariamis On

In case someone is searching for this.

I manage to do what i want with Passthrough Blocks and Pass Macro substitutions.

So my partial became

[pass,subs="+attributes,+macros"]
Hello {lang} World!

So now i have this

:lang: Java
include::partial$hello_world.adoc[]

:lang: PHP
include::partial$hello_world.adoc[]

and i get this

Hello Java World!Hello PHP World!
0
Peter Verhas On

I am not sure I get precisely what you are looking for. Still, I sense that you want some attribute replacement and text transformation (trim empty lines) functionality, which, in my opinion, is beyond the scope of Asciidoc or, for that matter, any other markup language.

To accommodate those needs, I developed a meta markup language in the last 27 years, Jamal, which now has a 5-year-old Java implementation integrated very well with Asciidoctor.

You can reach Jamal at https://github.com/verhas/jamal

With Jamal, you can include files, reformat the included lines with search and replace using regular expressions, delete certain lines, number the lines, and you can apply many other transformations.

Jamal is a macro language with built-in and user-defined macros, which can cover the functionality of Asciidoc attributes but provide many more features. For one: they can have attributes, which are substituted with the actual values at the location of use. Their resolution can include other macros, not only user-defined but also built-in.

When you use Jamal in Asciidoc, you can see the result in real-time using the Asciidoctor preprocessor in IntelliJ or AsciidocFX.

I do not say that Jamal is for everyone, but I feel that your problem is reaching out to the possibilities of Asciidoc formatting and entering the realms that Jamal was designed for. Excuse me if I misinterpreted your needs.