Login  Register

ifdef in a line

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options Options
Embed post
Permalink
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

ifdef in a line

ggenier
Hello everybody,

I search since a few day and I don't see anyone to this, so may be is not the good way to do this.

I want to include condition ifdef in my line.

For exemple :
Test ifdef::myAtt[new function]

When documentation was generated, I see "Test ifdef::myAtt[new function].", there is no remplacement of my text.

I I wrote :
Test
ifdef::myAtt[new function]

When documentation was generated, If see :

Test
new function

Problem is, my condition need to be on a new line and I have a carrier return.

Is it possible to have this on one line ?

Thanks in advance.

Grégoire
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: ifdef in a line

1marc1
Grégoire,

"ifdef" needs to be at the start of a new line. If I have the following in my source document:

Test
ifdef::myAtt[new function]

:myAtt:

Test
ifdef::myAtt[new function]

Then both the asciidoctor-pdf and HTML output render as:

Test

Test new function

I believe this is the result you are looking for.

Marc.
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: ifdef in a line

ggenier
Hello,

Thank you.

Ok, it's works. It is less readable on two line but I can do it :D
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: ifdef in a line

1marc1
Grégoire,

To make it more readable, you can consider doing something like this:

ifdef::myAtt[Test new function]
ifndef::myAtt[Test]

Or even add some comments to make it clearer:

// myAtt is defined
ifdef::myAtt[Test new function]

// myAtt is not defined
ifndef::myAtt[Test]

Marc.
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: ifdef in a line

ggenier
Hello,

Yes it works. For me it is not very natural.

For example for a sentence like this :

"If you want to run your program in production/test environment..."

Today, I need to write :

ifdef::production[If you want to run your program in production environment...]
ifdef::test[If you want to run your program in test environment...]

I think it will be easier to write :
"If you want to run your program in ifdef::production[production] ifdef::test[test] environment...]"

May be variables exist in asciidoctor and in this case I can use it ?

May be like this : If you want to run your program in ::environement:: environment"

No ?
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: ifdef in a line

1marc1
Grégoire,

If that is your use-case, then certainly a document attribute would be the way to go. You can then use that attribute in other parts of your document as well.

Here is how to do it:

:environment: production

If you want to run your program in a {environment} environment...

Just change the value of the :environment: attribute to whatever you want it to be.

Marc.