0

If I process the following asciidoc file with asciidoctor,

Here is our first program:
[source,cpp]
----
// Uninteresting/Potboiler line
// Uninteresting/Potboiler line
// Uninteresting/Potboiler line
// Uninteresting/Potboiler line
// Interesting line
// Interesting line
// Uninteresting/Potboiler line
// Uninteresting/Potboiler line
// Uninteresting/Potboiler line
// Uninteresting/Potboiler line
----

the result looks as follows:

Non-elided code

But often (as hinted in the code above) the crux of what's interesting is brief.

In such cases I can keep the entire HTML succinct by quoting just the interesting lines, and adding a link that points to the full source file. This takes the reader out of context, and forces them to go forward/back in the HTML navigation.

I am looking instead for a way to keep the full code accessible through scrolling in the html page, while showing only the interesting bits. Is this possible with asciidoctor?

Calaf
  • 10,113
  • 15
  • 57
  • 120

1 Answers1

0

The answer to your question can be found in the documentation in section 49.1 about includes. For the sake of keeping things all together, I'll also give a brief example here.

Use tags or line section when you do the include. If you use lines it'll look something like:

include::my_file[lines=5..7]

If you decide to use tags (which imo is better as you're less likely to have the two out of sync) it will look like this:

include::my_file[tags=interesting_part]

Then my_file would look like

Uninteresting line
Uninteresting line
Uninteresting line
// tag::interesting_part[]
Interesting line
Interesting line
// end::interesting_part[]
Uninteresting line
Uninteresting line

Use whatever kind of comment is correct for that particular file type in the file to be included.

LightGuard
  • 5,298
  • 19
  • 19
  • I am well aware of the tags feature, and I agree with you that tagging is safer than line quoting. But I am looking for a way for the complete file to be quoted within the html output, but only for the interesting lines to be initially visible. If the user so wishes, they can scroll within that code excerpt to see the surrounding lines. – Calaf May 29 '15 at 18:45
  • Ah. You'd probably have to write a custom extension to do that. – LightGuard May 29 '15 at 18:48