In a previous post we learned how to include parts of a document in the generated output. The included parts are defined using tags. The start of a tag is defined in a comment with the format tag::tagName[]
and the end has the format end::tagName[]
. Next we must use the tags
attribute for the include
macro followed by the tagName. If we don't want to include a tag we must prefix it with an exclamation mark (!
).
Suppose we have an external Java source we want to include in our Asciidoctor document.
1 2 3 4 5 6 7 8 9 | package mrhaki; // tag::singletonAnnotation[] @Singleton // end::singletonAnnotation[] public class Sample { public String greeting() { return "Hello Asciidoctor" ; } } |
In the following sample Asciidoctor document we include Sample.java
, but we don't want to include the text enclosed with the singletonAnnotation
tag. So we use tags=!singletonAnnotaion
with the include
macro:
1 2 3 4 5 6 7 | = Sample To NOT include sections enclosed with tags we must use `tags=!<tagName>` in the ` include ` directive. [source,java] ---- include ::Sample.java [tags=!singletonAnnotation] ---- |
When we transform our Asciidoctor markup to HTML we get the following result:
Written with Asciidoctor 1.5.6.1.