Conditional Attributes?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Conditional Attributes?

eskwayrd
Hi,

I'm trying to use conditional attribute values to use the correct image formats when producing HTML or PDF; I want PNG images included for HTML, and SVG images included for PDF.

According to the AsciiDoc docs here: http://www.methods.co.nz/asciidoc/chunked/ch28.html
Attribute references contained in the entry <value> will be expanded.

I'm probably doing something incorrectly, but I can't get this to work with AsciiDoctor. Given this document:
= Attribute Test
:foo: lish
:bar: {foo}
:qaz: wsx
:edc: {qaz@wsx:enabled:disabled}

Testing output of {foo} and {bar}.

Testing output of {qaz} and {edc}.

The (lightly trimmed) output is:
<div class="paragraph">
<p>Testing output of lish and lish.</p>
</div>
<div class="paragraph">
<p>Testing output of wsx and {qaz@wsx:enabled:disabled}.</p>
</div>

Shouldn't the last paragraph read:
<p>Testing output of wsx and enabled.</p>

Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: Conditional Attributes?

mojavelinux
Administrator

On Fri, May 1, 2015 at 11:51 AM, eskwayrd [via Asciidoctor :: Discussion] <[hidden email]> wrote:
According to the AsciiDoc docs here: http://www.methods.co.nz/asciidoc/chunked/ch28.html
Attribute references contained in the entry <value> will be expanded.

The feature you've pointed to is not implemented in Asciidoctor. We chose not to implement this feature to reduce complexity of attribute references in the document (and to increase speed). Fear not, what you want to do is still possible in Asciidoctor, but just through an alternate strategy. You have to use ifdef, ifndef and/or ifeval instead when assigning the attributes.

----
:edc: disabled
ifeval["{qaz}" == "wsx"]
:edc: enabled
endif::[]
----

If you are just checking for the existence of an attribute, the syntax is simpler:

----
:edc: disabled
ifdef::qaz[:edc: enabled]
----

I hope that helps.

Cheers,