Include sections of files
Posted by glaforge on Apr 11, 2013; 4:51pm
URL: https://discuss.asciidoctor.org/Include-sections-of-files-tp106.html
Hi all,
I don't think the genuine AsciiDoc supports this, nor AsciiDoctor, but please tell me if I'm wrong -- I'd be happy if I were!
Is there a way to just include certain bits of a file when using the include directive?
For example, I'd like to include some code samples in a document, by splitting the included file in several sections, separated by some narrative.
More concretely, imagine a Groovy script I want to embed, called foo.groovy:
class Foo {
static greet() { "hello" }
}
assert Foo.greet() == "hello"
I wish I could say:
Given a class:
include::foo.groovy[startLine=1, endLine=3]
Then you can run the following assert:
include::foo.groovy[startLine=4, endLine=4]
And you'd get the result:
Given a class:
class Foo {
static greet() { "hello" }
}
Then you can run the following assert:
assert Foo.greet() == "hello"
Basically, I'm looking forward to being able to put code snippets in external files and reference them easily, sometimes in chunks, in the document, so as to have the ability to run the external scripts as part of my unit tests, ie. I was thinking of using AsciiDoctor to write "executable specifications" :-)
Guillaume