Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to have modular AsciiDoc book (that consists of few files)?

Tags:

asciidoc

Considering that a book in DocBook format can be done in a "modular" fashion, I hoped I can do similar with AsciiDoc and split chapters and first-level sections in separate files. Unfortunately documentation does not say anything about this. The only possible solution I see so far is to write my own AsciiDoc preprocessor that will merge all "part"-files and generate the book. Did someone solve this problem by now?

like image 322
DejanLekic Avatar asked Apr 04 '12 14:04

DejanLekic


2 Answers

Two example ways from the asciidoc cheatsheet: http://powerman.name/doc/asciidoc

include::footer.txt[]

or

[source,perl]
----
include::script.pl[]
----
like image 117
sjas Avatar answered Oct 17 '22 23:10

sjas


I have set up a book template that I use in all by book, you can find it here: asciidoc-book-template-with-rake-and-github

= Nome da disciplina
:doctype: book
:lang: pt-BR
:ascii-ids:
:showcomments:
:gitrepo: https://github.com/xxx/yyy
:code_dir: code
:image_dir: imagens

include::capitulos/prefacio.adoc[]

////
= Nome da Parte =
////

include::capitulos/cap1.adoc[]

include::capitulos/feedback.adoc[]

include::capitulos/cap2.adoc[]

include::capitulos/feedback.adoc[]

include::capitulos/cap3.adoc[]

include::capitulos/feedback.adoc[]

// ...

include::capitulos/glossario.adoc[]

include::capitulos/respostas.adoc[]

////
Always end files with a blank line to avoid include problems.
////

Note the blank lines between the include directives: they prevent the first and last lines of the included files from being adjoined. I don't split chapter on more files because when you include a file asciidoc takes the included file path to be the parent of new includes, look this tree:

.
|-- capitulos
|   |-- cap1.adoc
|   |-- cap2.adoc
|   |-- cap3.adoc
|   |-- code
|   |   `-- cap1
|   |       |-- helloworld.c
|   |       `-- Makefile
|   |-- feedback.adoc
|   |-- glossario.adoc
|   |-- prefacio.adoc
|   |-- respostas.adoc
|   `-- symbols.adoc
|-- docinfo.xml
|-- livro.asc
`-- wip.adoc
  • When I'm at the file livro.adoc and I what to include feedback.adoc I will use include::capitulos/feedback.adoc[]
  • But if I'm at the file cap1.adoc you will have to use include::feedback.adoc[] (since they are at the same directory).

I think it's more easy to keep all includes in one same place, it works for me. I only include codes using the other way.

like image 15
Eduardo Santana Avatar answered Oct 18 '22 01:10

Eduardo Santana