Re: Attribute substitution inside source block

Posted by mojavelinux on
URL: https://discuss.asciidoctor.org/Attribute-substitution-inside-source-block-tp406p409.html

https://github.com/asciidoctor/asciidoctor/issues/522 - Allow substitutions to be added or removed individually

-Dan


On Mon, Jul 29, 2013 at 12:44 PM, Dan Allen <[hidden email]> wrote:
Btw, I'm thinking of a +/- prefix to allow substitutions to be added and removed without having to specify all of them. For instance:

[source,xml]
[subs="+attributes"]
.maven dependency 
----
<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-search</hibernate-search>
  <version>{version}</version>
</dependency>
----

This one would remove the callouts substitution:

[subs="-callouts"]

The plus would always append to the default list. If you need a specific order, then you would need to specify it explicitly. (Unless you have another idea).

-Dan



On Mon, Jul 29, 2013 at 12:41 PM, Dan Allen <[hidden email]> wrote:
Emmanuel,

Good news, AsciiDoc provides a way! (which is faithfully implemented by Asciidoctor).

Just about anywhere in AsciiDoc you can control which substitutions are used. In your case, you are interested in the "attributes" substitution.

Here's how to control it.

[source,xml]
[subs="verbatim,attributes"]
.maven dependency 
----
<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-search</hibernate-search>
  <version>{version}</version>
</dependency>
----

(I use two attribute lines to be compatible with AsciiDoc. Asciidoctor properly handles putting them all in one line).

The only downside is that you have to specify all the substitutions you want when you override. That's why the "verbatim" is necessary. "verbatim" is an alias for "specialcharacters,callouts". So the effective substitutions are now "specialcharacters,callouts,attributes".

Please note that this will not work in the preview on GitHub since it was implemented in a later version than they are running (I'm still working on getting them upgraded).

Also, I'll add this to the quick reference guide since the question has come up a few times now.

-Dan


On Mon, Jul 29, 2013 at 7:45 AM, Emmanuel Bernard [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Hey all,

I get that source blocks don't enjoy substitutions which would be dangerous OOTB but how would you solve such scenario

= Some getting started guide
Emmanuel
:version: 1.0.0.Final

To embed your library, use the following maven snippet

[source, xml]
.maven dependency
----
<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-search</hibernate-search>
  <version>{version}</version>
</dependency>
----

Today the {version} string is reproduced verbatim. how would you address this use case?

Emmanuel


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Attribute-substitution-inside-source-block-tp406.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--



--



--
Dan Allen | http://google.com/profiles/dan.j.allen