Dark theme | Light theme

August 5, 2014

Awesome Asciidoctor: Include Only Certain Lines from Included Files

In a previous post we learned how to include partial content from included files. We needed to enclose the content we want to include between start and end tags and reference those tags in our documentation markup. But Andres Almiray already mentioned in a tweet we can use line numbers as well:

Let's see this in action in our Asciidoc markup. We can use the include macro and specify the lines we want to include with the lines attribute. We can include multiple lines by specifying a range (1..10), or separate different line sections with a ;. To indicate we want to include lines from a starting line up until the end of the file we can use -1 to indicate the end of the file.


Here is the source of the file we want to include:

package com.mrhaki.groovy

 * Sample Groovy class with
 * two properties.
class User {
    String name
    String email

And when we generate an HTML version of our markup we see that only part of the original source file is included in the output:

Written with Asciidoctor 0.1.4.