Login  Register

Re: Include sections of files

Posted by mojavelinux on Apr 11, 2013; 8:48pm
URL: https://discuss.asciidoctor.org/Include-sections-of-files-tp106p113.html




On Thu, Apr 11, 2013 at 2:22 PM, lightguard.jp [via Asciidoctor :: Discussion] <[hidden email]> wrote:



On Thu, Apr 11, 2013 at 11:50, mojavelinux [via Asciidoctor :: Discussion] <[hidden email]="mailto:[hidden email]">> wrote:

That is precisely one of the features on the roadmap. In fact, it's high priority because we need it to migrate the Arquillian tutorials to AsciiDoc (using Asciidoctor).

Where we are right now is sorting out the syntax for marking the code to be inserted and inserting the code.

My working proposal is to tag the code as follows:

// tag: classdef
class Foo {
    static greet() { "hello" }
}
// tag: classdef

Then use a block macro to insert it:

source::foo.groovy[classdef]

I'd also like to support a resolver that could locate the file in an archive like a jar, a path like an output directory or even a URL.

I'm open to support line number ranges in the include macro, but I don't want to recommend that as the way to go because it's terribly brittle. There will be times when it is needed, so I don't want to deny that ability. I was thinking something like:

include::foo.groovy[from=1, to=3]

I'll make sure there is an issue for this feature and link it here.

​What about

include::foo.groovy[range=1..3]

Yep, I like that. I was thinking we could even make range (or lines) a positional attribute so it can be written shorthand as:

include::foo.groovy[1..3]

We have to be sure, though, that there is no better use for the first positional attribute. We could start with range (or lines) and then decide later to introduce the shorthand.

include::foo.groovy[lines=1..3]

-Dan

--
Dan Allen
Principal Software Engineer, Red Hat | Author of Seam in Action
Registered Linux User #231597

http://google.com/profiles/dan.j.allen
http://mojavelinux.com
http://mojavelinux.com/seaminaction