Search code examples
asciidocarc42

Asciidoc define variable local to file


I'm using the arc42 template to create my documentation. It has a structure with a main file that includes files that contain the various chapters. I'd like to redefine a variable that is local to one of that chapters but it's not visible outside that specific file, and the outside variable value is the one set on the main file. In particular, i'm trying to redefine imagedir inside 05_building_block_view.adoc as: :imagesdir: ./diagrams, but then in the following chapters, it keeps that value and not the default one. So the general question is:

Is it possible to define a local to file variable in Asciidoc?


Solution

  • No. Attribute definitions are global. Asciidoctor performs single-pass parsing, so attributes are not defined until the line processor encounters the definition.

    You could use another attribute to "backup" an attribute, change the attribute, and when "done", reinstate the original from the backup. For example:

    :foo: bar
    Foo is currently {foo}.
    
    :backupfoo: {foo}
    :foo: xyz
    Foo is currently {foo}.
    
    :foo: {backupfoo}
    Foo is currently {foo}.
    

    That outputs:

    Foo is currently bar.
    
    Foo is currently xyz.
    
    Foo is currently bar.