Mapping AsciiDoc includes and level offsets to Jinja
Jinja natively supports including text files with {% include ... %}:
- Migrating AsciiDoc to Markdown
- Why existing AsciiDoc converters lose your structure
- Why Jinja is the right target
- Mapping AsciiDoc variables to Jinja
- Mapping AsciiDoc conditionals to Jinja
- Mapping AsciiDoc ifeval to Jinja
- Mapping AsciiDoc includes and level offsets to Jinja — you are here
- AsciiDoc:asciidoc
include::snippets/deployment-config-deprecated.adoc[] - Jinja:jinja
{% include "./snippets/deployment-config-deprecated.md" %}
That much is free. Level offsets are not.
Level offsets
By default Jinja does not support level offsets — shifting heading levels up or down when merging files together.
Level offsets solve a real problem in technical writing: modular reuse. They let you write a file as a standalone document, with its own primary = Title, and then embed it as a nested subsection inside a master book or assembly without breaking the global table of contents.
DogsBay extends Jinja with {% leveloffset ... %} and {% endleveloffset %}:
- AsciiDoc:asciidoc
include::modules/ldap-syncing-about.adoc[leveloffset=+1] include::modules/ldap-syncing-config-rfc2307.adoc[leveloffset=+2] include::modules/ldap-syncing-config-activedir.adoc[leveloffset=+2] include::modules/ldap-syncing-running.adoc[leveloffset=+1] - Jinja:jinja
{% leveloffset +1 %}{% include "./modules/ldap-syncing-about.md" %}{% endleveloffset %} {% leveloffset +2 %}{% include "./modules/ldap-syncing-config-rfc2307.md" %}{% endleveloffset %} {% leveloffset +2 %}{% include "./modules/ldap-syncing-config-activedir.md" %}{% endleveloffset %} {% leveloffset +1 %}{% include "./modules/ldap-syncing-running.md" %}{% endleveloffset %}
Watch the code blocks. A heading shift must not change # characters that are shell prompts or comments inside a fenced code block. The shift has to be fence-aware, so # oc adm ... in a terminal block stays a comment and does not become a heading.
That warning is not hypothetical. In an operations corpus, # opens a large proportion of the lines inside code blocks — a naive regex shift corrupts them all, and the damage looks like ordinary prose in the diff.
Reference: Syncing LDAP groups
That completes the mapping. Back to the series index.