Process Multiple Source Files from the CLI

You can pass multiple source files or a filename pattern to the Asciidoctor CLI and it will convert each file given in turn.

Let’s assume there exist two AsciiDoc files in the current directory, a.adoc and b.adoc. You can pass both files to Asciidoctor using a single command, as follows:

$ asciidoctor a.adoc b.adoc

Asciidoctor will convert both files, transforming a.adoc to a.html and b.adoc to b.html.

To save some typing, you can use the glob operator (*) to match all AsciiDoc files in the current directory using a single argument:

$ asciidoctor *.adoc

Your shell will automatically expand the pattern and interpret the command exactly as you had typed it above:

$ asciidoctor a.adoc b.adoc

You can pass all AsciiDoc files inside direct subfolders using the glob operator (*) in place of the directory name:

$ asciidoctor */*.adoc

To match all files in the current directory and direct subfolders, combine both glob patterns:

$ asciidoctor *.adoc */*.adoc

Since the globs in this command rely on shell expansion, the command is not portable across platforms. To make it portable, you can allow the Asciidoctor CLI to expand the globs. To do so, instruct the shell to not expand the glob by quoting the pattern, as shown here:

$ asciidoctor '*.adoc' '*/*.adoc'

This time, the arguments *.adoc and */*.adoc are passed directly to Asciidoctor instead of being expanded. Asciidoctor handles the glob matching in a manner that is portable across platforms.

But it gets better. The glob handling in Asciidoctor (which matches the rules of file globbing in Ruby) is likely more powerful than what your shell offers. For example, you can match AsciiDoc files in the current folder and in folders of any depth using the double glob operator (**).

$ asciidoctor '**/*.adoc'

Most shells do not honor this double glob pattern.

In conclusion, when specifying a glob pattern, we always recommend enclosing the argument in quotes.

If you process multiple nested AsciiDoc files at once and applying a custom stylesheet, you’ll need to manage the stylesheet’s location.