asciidoctor

How do I define a substitution on Asciidoctor.convert


I want to specify a string value for the Ruby API of Asciidoctor, and want to have Asciidoctor substitute that value into the output.

I pieces the following together from the documentation, but it does not work.

Asciidoctor.convert adoc, attributes: { updated: src_mtime }

where adoc is a string like this:

:title: Some Title
:hardbreaks:

Introductory paragraph

== Section title

Paragraphs

[.text-right]
Last updated: {updated}

This will just generate "Last updated: {updated}" in the last paragraph, no substitution applied.

If I define updated as a header attribute, like so :updated: 1 Jan 2000, the substitution does take place, but it ignores the attributes from the Asciidoctor.convert call.

I've been banging my head on this all day, but to no avail.


Solution

  • Turns out the real issue was with the way the hash was constructed.

    { updated: src_mtime } creates a hash with a symbol as key.
    { 'updated' => src_mtime } creates a hash with a string as key.

    Asciidoctor uses only string-keyed entries when looking for substitutions.