Outputting asciidoc?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Outputting asciidoc?

joster
This might seem like a frivolous use case, but I'm finding myself actually in need of it. I have an asciidoc file with a number of includes, even nested inside each other. I can output html or any of the other rendered formats if I want to, but what I really want is a flat asciidoc file, with no includes, that I can work on and pass to someone else. Is it possible for asciidoctor to output an asciidoc file with the includes resolved?

I've tried using an asciidoctor -> docbook -> pandoc -> asciidoc toolchain, but that messes everything up badly.
Reply | Threaded
Open this post in threaded view
|

Re: Outputting asciidoc?

jvdh
I've had that problem once with AsciiDoc -- don't know whether asciidoctor  
provides a solution out of the box. anyway, this script
 
#--------------------CUT HERE-------------------------------------
 
#!/bin/sh
# -------------------------------------------------------------
# replace asciidoc `include::' macros by the referenced content
# -------------------------------------------------------------
awk '
    BEGIN {
       inca = "^include::"
       incb = "\\[.*\\][ \\t]*$"
       name = ".+"
       incab =  inca name incb
    }
    $0 ~ incab {
       match($0, inca)
       fnam = substr($0, RSTART+RLENGTH)
       match(fnam, incb)
       fnam = substr(fnam, 1, RSTART-1)
 
       print "// ********** start of expansion of", fnam, "********** //"
       while (getline <fnam >0) print
       close(fnam)
       print "// ********** end of expansion of", fnam, "************ //"
 
       next
    }
    {
       print
    }
'
 
#--------------------CUT HERE-------------------------------------
 
should do what you want. if you name this script, e.g., `inflate' you can  
use it like
 
cat mydoc.txt | inflate > newdoc.txt
 
as you can see, it acts as filter between stdin and stdout and brackets  
the included stuff in comment lines in the output indicating which files  
are included.
 
hth
 
joerg
 
Reply | Threaded
Open this post in threaded view
|

Re: Outputting asciidoc?

mojavelinux
Administrator
In reply to this post by joster
@joster, you're not alone. This use case comes up often. I've written a coalescer script that does exactly what you describe (fairly well). It could definitely stand to be improved.


If there is something missing from that script, please report it.

It's important that we use the Asciidoctor line reader to handle this requirement as it understands the structure of the document. Any external regexp-based approach may work for simple documents, but quickly breaks down because it is not considering all of the AsciiDoc rules.

Cheers,

-Dan

On Wed, Mar 30, 2016 at 4:30 AM, joster [via Asciidoctor :: Discussion] <[hidden email]> wrote:
This might seem like a frivolous use case, but I'm finding myself actually in need of it. I have an asciidoc file with a number of includes, even nested inside each other. I can output html or any of the other rendered formats if I want to, but what I really want is a flat asciidoc file, with no includes, that I can work on and pass to someone else. Is it possible for asciidoctor to output an asciidoc file with the includes resolved?

I've tried using an asciidoctor -> docbook -> pandoc -> asciidoc toolchain, but that messes everything up badly.


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Outputting-asciidoc-tp4567.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--
Dan Allen | @mojavelinux | http://google.com/profiles/dan.j.allen
Reply | Threaded
Open this post in threaded view
|

Re: Outputting asciidoc?

joster
That's fantastic, and exactly what I was looking for. Thank you very kindly!

There's one exceedingly minor issue I ran into with an easy workaround, but I went ahead and opened an issue for it anyway, in case it's of interest.

https://github.com/asciidoctor/asciidoctor-extensions-lab/issues/62

Thanks again!
Reply | Threaded
Open this post in threaded view
|

Re: Outputting asciidoc?

mojavelinux
Administrator

On Thu, Mar 31, 2016 at 10:38 AM, joster [via Asciidoctor :: Discussion] <[hidden email]> wrote:
That's fantastic, and exactly what I was looking for. Thank you very kindly!

Great news!

-Dan


--
Dan Allen | @mojavelinux | http://google.com/profiles/dan.j.allen