This document describes every option available when using asciidoc-php,
both from the command line and from the PHP API.
1. Command-line Interface
The bin/asciidoc-php binary converts one or more AsciiDoc source files to the
configured output format.
1.1. Synopsis
asciidoc-php [options] FILE [FILE ...]
asciidoc-php [options] - # read from STDIN, write to STDOUT
1.2. Options
1.2.1. -b, --backend BACKEND
Select the output backend.
| Value | Description |
|---|---|
|
HTML 5 output via the bundled |
Only html5 is implemented in v0.1. The flag is accepted for
forward-compatibility.
|
1.2.2. -d, --doctype DOCTYPE
Set the document type, which controls which structural sections are valid and how the header is rendered.
| Value | Description |
|---|---|
|
Standard article — single-part document |
|
Multi-part book — accepts |
|
UNIX man-page — |
|
Fragment — renders a single inline paragraph, no block wrapper |
1.2.3. -o, --out-file FILE
Write the converted output to FILE instead of the default location.
-
Use
-to write to STDOUT. -
When converting multiple input files this flag applies to every file in sequence; prefer
--destination-dirfor batch conversion.
1.2.4. -D, --destination-dir DIR
Place all converted output files into DIR.
-
The directory is created automatically (including intermediate directories) if it does not exist.
-
Each output file is named after the input file with its extension replaced by
.html.
asciidoc-php -D html/ docs/*.adoc
1.2.5. -B, --base-dir DIR
Override the base directory used to resolve include:: directives.
-
Defaults to the directory of the input file when
--out-file/ a positional path is given, or the current working directory for STDIN.
1.2.6. -S, --safe-mode MODE
Control which features are available based on trust level.
| Value | Integer | Description |
|---|---|---|
|
0 |
All features enabled; use only for fully trusted input |
|
1 (default) |
Standard restrictions; external includes allowed from within |
|
10 |
Stricter; restricts access to the filesystem above |
|
20 |
Maximum restriction; |
1.2.7. -a, --attribute KEY[=VALUE]
Set (or unset) a document attribute. Repeatable.
| Form | Effect |
|---|---|
|
Sets |
|
Sets |
|
Explicitly unsets |
Attributes set via -a are applied before the document header is read,
so they can be referenced in the source. They cannot be overridden by
attribute entries in the source file (they are locked).
Common attributes you may want to set via -a:
| Attribute | Purpose |
|---|---|
|
Enable table of contents ( |
|
Override TOC heading text (default: |
|
Auto-number sections |
|
Enable icons; set to |
|
Syntax highlighter ( |
|
Strip leading YAML front matter before parsing (see YAML Front Matter) |
|
Base path prepended to all |
|
Enable UI macro ( |
|
Inject external docinfo files ( |
1.2.8. -s, --no-header-footer
Produce an embedded (fragment) document — omit the <html>, <head>,
and <body> wrapper elements. Useful when embedding the output into an
existing page.
1.2.9. --concurrency N
Maximum number of files to convert concurrently when processing multiple input files.
| Value | Behaviour |
|---|---|
|
Sequential (no concurrency) |
Any positive integer |
Cap concurrent conversions at N |
1.2.10. -q, --quiet
Suppress all informational messages. Only fatal errors are written to
STDERR.
1.2.11. -v, --verbose
Log each converted file to the logger (or STDOUT) after it completes.
1.2.12. -t, --timings
Print a timing breakdown for each file after conversion.
1.2.13. --trace
Print a full PHP stack trace when a conversion error is caught. Without this flag only the error message is shown.
1.2.14. -h, --help
Print the help message and exit with code 0.
1.2.15. --version
Print the library version string and exit with code 0.
1.3. Examples
asciidoc-php docs/guide.adoc
asciidoc-php -a toc=left docs/guide.adoc
asciidoc-php -D html/ docs/*.adoc
cat fragment.adoc | asciidoc-php -s -o - -
asciidoc-php -a toc=left -a sectnums -a icons=font docs/guide.adoc
asciidoc-php -a skip-front-matter docs/page.adoc
asciidoc-php -q -D out/ docs/*.adoc
2. PHP API
2.1. Asciidoc::convert()
Convert an AsciiDoc string directly.
use Webware\AsciidocPhp\Asciidoc;
$html = Asciidoc::convert($source, $opts);
$source is any valid AsciiDoc string. $opts is an optional
associative array — see API Option Keys for all recognised keys.
2.2. Asciidoc::convertFile()
Read an AsciiDoc file from disk and convert it.
$html = Asciidoc::convertFile('/path/to/guide.adoc', $opts);
-
Throws
\RuntimeExceptionif the file does not exist or cannot be read. -
base_dirdefaults todirname($path)when not supplied.
2.3. API Option Keys
| Key | Type | Default | Description |
|---|---|---|---|
|
|
|
Output backend. Currently only |
|
|
|
Document type: |
|
|
|
Trust level. Pass a |
|
|
|
Initial document attributes. |
|
|
|
When |
|
|
|
Base directory for |
|
|
|
Custom converter instance. Implement
|
|
|
|
Attach source-location metadata to AST nodes (for tooling / IDE use). |
2.4. API Examples
$html = Asciidoc::convert('= Hello World');
$fragment = Asciidoc::convert($source, ['header_footer' => false]);
$html = Asciidoc::convert($source, [
'attributes' => [
'toc' => 'left',
'sectnums' => '',
'icons' => 'font',
'source-highlighter' => 'highlight.js',
],
]);
use Webware\AsciidocPhp\Asciidoc;
use Webware\AsciidocPhp\Document;
use Webware\AsciidocPhp\Parser\Parser;
use Webware\AsciidocPhp\Reader\Cursor;
use Webware\AsciidocPhp\Reader\PreprocessorReader;
// High-level: skip-front-matter via the facade
$html = Asciidoc::convertFile('page.adoc', [
'attributes' => ['skip-front-matter' => ''],
]);
// The raw YAML block is available as the `front-matter` document attribute
// after the parse if you work at the lower-level API.
use Webware\AsciidocPhp\SafeMode;
$html = Asciidoc::convertFile('untrusted.adoc', [
'safe' => SafeMode::SECURE,
]);
3. YAML Front Matter
When the skip-front-matter attribute is set, asciidoc-php recognises
a YAML front matter block at the very start of the document.
3.1. Format
The block is delimited by --- on its own line, must begin on the first
line of the file, and must be closed by a second --- line before any
AsciiDoc content.
---
layout: default
title: "My Page"
author: Alice
---
= My Page
Alice
:toc: left
Document body starts here.
3.2. Behaviour
| Rule | Detail |
|---|---|
Activation |
Front matter is only parsed when |
Storage |
The raw YAML text (between the delimiters, delimiters excluded) is stored in the |
Attribute promotion |
Simple scalar |
Quote stripping |
Values wrapped in |
No override |
A promoted key never overwrites an attribute already set on the document (e.g. via |
Unclosed block |
If no closing |
3.3. Activating via CLI
asciidoc-php -a skip-front-matter docs/page.adoc
3.4. Activating via API
$html = Asciidoc::convertFile('page.adoc', [
'attributes' => ['skip-front-matter' => ''],
]);
4. Document Attributes Reference
The following built-in attributes are set automatically on every document.
They can be read by the document source, overridden via -a / attributes,
or queried from Document::getAttribute().
4.1. Read-only (set by the converter)
| Attribute | Value |
|---|---|
|
Library version string (e.g. |
|
Same as |
|
Active backend name (e.g. |
|
Base backend family ( |
|
Active doctype (e.g. |
|
Always |
|
Output file type (e.g. |
|
Output file extension (e.g. |
|
Date the document was converted ( |
|
Time the document was converted ( |
|
Date + time combined |
|
Same as |
|
Same as |
|
Same as |
4.2. Configurable
| Attribute | Default | Description |
|---|---|---|
|
(unset) |
Enable TOC and set placement: |
|
|
Heading text shown above the TOC |
|
|
Alternative placement key; |
|
(unset) |
Auto-number sections when set |
|
(unset) |
Prepend anchor links to section titles when set |
|
(unset) |
Make section titles clickable anchor links when set |
|
(unset) |
Set to |
|
(unset) |
Set to |
|
(unset) |
Strip leading YAML front matter when set |
|
(unset) |
Prepended to all |
|
(unset) |
Enable UI macros ( |
|
|
Label for CAUTION admonition blocks |
|
|
Label for IMPORTANT admonition blocks |
|
|
Label for NOTE admonition blocks |
|
|
Label for TIP admonition blocks |
|
|
Label for WARNING admonition blocks |
|
|
Caption prefix for auto-numbered tables |
|
|
Caption prefix for auto-numbered figures |
|
|
Caption prefix for auto-numbered examples |