Custom Layout
It’s also possible to create your own layout by extending the default HTML 5 converter. To create a new layout, you will need some JavaScript knowledge.
Let’s say that we want to override how the document node is converted:
export default {
document: async (node) => `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link href="./layout.css" rel="stylesheet">
</head>
<body>
${await node.getContent()}
</body>`,
}
The template file is an ES module and exports an object whose keys are node names and whose values are (possibly async) converter functions.
You can also override other elements.
Complete list of elements
-
document -
embedded -
outline -
section -
admonition -
audio -
colist -
dlist -
example -
floating-title -
image -
listing -
literal -
stem -
olist -
open -
page_break -
paragraph -
preamble -
quote -
thematic_break -
sidebar -
table -
toc -
ulist -
verse -
video -
inline_anchor -
inline_break -
inline_button -
inline_callout -
inline_footnote -
inline_image -
inline_indexterm -
inline_kbd -
inline_menu -
inline_quoted
The function takes one parameter, called node.
Depending on the context, a node can be a Block, a Section, a List, or a Table.
Block, Section, List, and Table extend AbstractBlock, which extends AbstractNode.
If you want to learn more, see the Asciidoctor.js API documentation.
To help you get started, we provide a few alternative layouts in the examples directory:
| Layout | Template file |
|---|---|
Letter |
|
Book |
|
Presentation |
|
Resume |
|
Cheat sheet (Snyk) |
To enable a custom layout, use the --template-require command line option.
For instance, if you want to use the cheat sheet layout on examples/cheat-sheet/maven-security-cheat-sheet.adoc:
asciidoctor-web-pdf ./examples/cheat-sheet/maven-security-cheat-sheet.adoc --template-require ./examples/cheat-sheet/snyk/template.js
It will produce a file named examples/cheat-sheet/maven-security-cheat-sheet.pdf.