Parsing Asciidoc file and including them into document in asciidoctor-pdf

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

Parsing Asciidoc file and including them into document in asciidoctor-pdf


I'm currently in the process of building the preprint of my books and am looking for a way to get the colophon directly after the title page, while still keeping the colophon content somewhat dynamic.

Inspired by this issue, the best way I found so far (save from generating the page separately and then inserting them into the PDF), is to overload the layout_title_page method with an extension, that I load over the -r switch in my asciidoctor-pdf execute

Right now, I've come this far in my layout_title_page-overload:

def layout_title_page doc
  colophon = File.readline('foo.adoc')
  colophon.each do |line|
    layout_prose line

This succeeds in so far, that the file foo.adoc is read linewise and put on the newly added page. But of course, nothing about this is in any way asciidoctor formatted. No formatting is preserved, and also multi-line paragraphs are split up into separate paragraphs.

As I am really not familiar with the inner workings of asciidoctor(-pdf), my question would be: Is there a good way to parse an adoc-file into an array of formatted asciidoctor text items or nodes (i guess that how it works?) which I then can put onto the page one by one?

This also should make it able to calcuate the height of the colophon to align it at the bottom.