Over a million developers have joined DZone.

Awesome Asciidoctor: Exclude Parts from Included Files

DZone's Guide to

Awesome Asciidoctor: Exclude Parts from Included Files

We show how to exclude certain parts from files that have been included in Asciidoctor.

· Open Source Zone ·
Free Resource

 tagName  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.

package mrhaki;

// tag::singletonAnnotation[]
// 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:

= Sample

To NOT include sections enclosed with tags we must use `tags=!<tagName>` in the `include` directive.


When we transform our Asciidoctor markup to HTML we get the following result:

Written with Asciidoctor

asciidoctor ,open source ,files ,code ,documentation

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}