Reference
Command-line interface
This page describes the adocfmt command: its flags, which files it reads, its exit codes, and the findings it reports.
Usage
adocfmt README.adoc # prints the formatted file
adocfmt --write docs # formats the AsciiDoc files under docs/ in place
adocfmt --check docs # lists the files that are not formatted
adocfmt --check docs README.adoc # checks several paths in one runadocfmt --help prints the flags.
The command takes the form adocfmt [flags] [path …].
Flags
-w,--writeWrites the formatted result back to every file that changes. A file that is already formatted is not touched. It needs at least one path. It prints nothing for the files it writes. For a symlink, it writes the file that the link points to and leaves the link in place.
-c,--checkChanges no file. Lists on stdout every file that is not formatted, one path per line, and exits with 1 if it lists any. A file that is formatted is not listed. Without a path, it reads stdin and prints
<stdin>if the input is not formatted. You cannot combine it with--write. For example, if onlydocs/setup.adocis not formatted,adocfmt --check docsprints:docs/setup.adoc
--versionPrints the version.
-h,--helpPrints the help.
Formatting to stdout
Without --write or --check, adocfmt formats one document and writes the result to stdout.
With no path, it reads stdin.
With one file, it reads that file and leaves it unchanged.
A directory or a second path is an error. To format several files, use
--write.
For example, printf '## Title\n' | adocfmt prints:
== Title
Stdout carries the formatted document, the file names from --check, and the output of --help and --version.
Everything else goes to stderr.
Which files are collected
You can name any number of files and directories. A file you name on the command line is formatted whatever its extension.
A directory you name is walked, including its subdirectories.
The walk collects every regular file whose name ends in .adoc or .asciidoc, in any letter case, so OLD.ASCIIDOC is collected too.
Directories whose names start with a dot are walked like any other.
- Symlinks
A symlink you name on the command line is followed, whether it points to a file or a directory. A symlink the walk finds inside a directory is skipped, whether it points to a file or a directory. So no file is formatted twice through a link.
- Order
Paths are processed in the order you name them. Inside a directory, the walk visits the entries in byte order of their names, so
Z.adoccomes beforea.adoc. A subdirectory is walked at its place in that order.- Names
adocfmt reports each file under the path you typed. Here
site-linkis a symlink to the directorysite, andadocfmt --check site-linkprints:site-link/index.adoc
- Errors
A path or file that cannot be read is reported and skipped, and the run goes on with the rest. If a subdirectory cannot be read, only the files inside it are skipped. In this example,
p/lockedcannot be read, andadocfmt --check pprints:adocfmt: open p/locked: permission denied p/open/a.adoc
Leave a file unformatted
A file that carries the comment // adocfmt: ignore-file above its document title stays exactly as it is:
--writedoes not touch the file.--checkdoes not list it and exits with 0 for it.Without either flag, adocfmt writes the input to stdout byte for byte, from a file or from stdin.
// adocfmt: ignore-file tables aligned by hand
= API reference- Spelling
Two slashes, then any number of spaces or tabs, then
adocfmt: ignore-filein lowercase, with one space after the colon. After it, a space or a tab can start a reason, which adocfmt ignores. Spellings such as// ADOCFMT: ignore-file,// adocfmt-ignore-fileor// adocfmt ignore-fileare ordinary comments.- Placement
Only blank lines, other comment lines and comment blocks may stand above the comment, after the YAML front matter if the file has any. The comment must be a comment line of its own, not a line inside a
////comment block.Stays unformatted--- title: API reference --- // Tables aligned by hand. // adocfmt: ignore-file = API referenceGets formatted= API reference // adocfmt: ignore-file :toc:
Exit codes
0Success. The document was written to stdout, the files were written, or
--checkfound every file formatted.--helpand--versionexit with 0 too.1--checkfound at least one file that is not formatted. Only--checkexits with 1.2An error. Either the command line is wrong, a path or file cannot be read or written, or adocfmt refused a document.
If a run finds both an error and a file that is not formatted, it exits with 2.
adocfmt goes on after an error, so one run reports every file that is not formatted and every error. A wrong command line is the exception: adocfmt reports it and stops before it reads any file.
In this example, adocfmt --check docs refuses docs/broken.adoc, still lists the two other files that are not formatted, and exits with 2:
docs/OLD.ASCIIDOC docs/broken.adoc:3: block has no closing delimiter docs/guide/setup.adoc
Refusal findings
adocfmt refuses a document when it meets structure it cannot read reliably.
It reports every finding in the document, writes no output for it, and leaves the file as it is.
With --write, the other files of the run are still written.
For the reasons, see Why a document with findings is refused whole.
Each finding is reported on stderr as <path>:<line>: <message>, the form that editors such as Vim read to jump to the line.
When adocfmt reads stdin, <path> is <stdin>.
Fix the document, then run adocfmt again.
block has no closing delimiterThe reported line is an opening delimiter, such as
----or====, and no later line matches it. The block runs to the end of the file. Add a closing line equal to the opening one. A fenced code block that opens with a language, such as```ruby, closes with the bare fence```.closes the block opened above itThe reported line equals the opening delimiter of an enclosing block, but it stands inside a nested block. Asciidoctor ends the enclosing block at this line, which is not what the nesting suggests. In this example, the
====on line 3 ends the example block, not a line of code:==== ---- ==== ---- ====
Make the two delimiters differ, for example by lengthening the outer one to
=====.delimiter opens and closes in different conditional regionsA block opens inside a conditional region and closes outside it, or the other way around. A conditional region is the part between an
ifdef,ifndef, orifevaldirective and itsendif. The reported line is the opening delimiter. Move the delimiters so that both are inside the region, or both outside it. This block opens inside the region and closes outside it:ifdef::extra[] ---- endif::[] code ----
conditional region has no endifThe directive on the reported line opens a conditional region, and no
endif::[]closes it. Add theendif::[]where the region ends.endif closes no conditional regionThe
endifon the reported line has no open region to close. Remove it, or add the directive that opens the region.malformed preprocessor directiveAsciidoctor rejects the directive on the reported line. An
ifdeforifndefneeds an attribute name, as inifdef::name[]. Anifevalneeds an expression in the brackets and nothing before them, as inifeval::[{level} > 1]. A malformed directive opens no region, so itsendifis reported as well. For example,printf 'ifdef::[]\nText.\nendif::[]\n' | adocfmt --checkprints:<stdin>:1: malformed preprocessor directive <stdin>:3: endif closes no conditional region
Documents adocfmt cannot read
Three problems concern the whole file, so their message has no line: <path>: <message>.
adocfmt refuses the document in the same way.
source is not valid UTF-8Convert the file to UTF-8.
source has mixed line endings: 1 CRLF, 1 LFSome lines end with a carriage return and a line feed, as on Windows, and others with a line feed alone. The message counts both. Convert the file to one of the two.
source has carriage returns that end no lineThe file holds a carriage return that is not followed by a line feed. Remove it, or replace it with a line ending.