asciidoctor/asciidoctor.js

Attributes not passed properly to Included Documents

reliable-jschacter opened this issue · 4 comments

Included documents with conditional directives refering to attributes from the parent are not being processed:

top-level doc:

:toc: macro
:myvar: true

toc::[]

== Heading 1

== Heading 2

include::./include/Nested1.adoc[]

included doc:

:toc: macro

ifndef::myvar[]
toc::[]
endif::[]

== nestedHeading 1

text

Result: ToC is still generated in included doc, not properly respecting myvar defined in the parent
Output of document.reader.read():

:toc: macro
:myvar: true

toc::[]

== Heading 1

== Heading 2

:toc: macro

toc::[]

== nestedHeading 1

text

I cannot reproduce, could you please explain how do you convert your AsciiDoc file?

Sure thing, nothing unusual going on here

    const asciidoctor = require('asciidoctor')();
    const doc = asciidoctor.loadFile(sourcePath, {
        safe: 'unsafe',
        parse: false,
        logger: new asciidoctor.NullLogger()
    });
    doc.reader.readLines()

I don't know why you want the retrieve the AsciiDoc after preprocessing/parsing but you should use:

const asciidoctor = require('asciidoctor')()
const doc = asciidoctor.loadFile('main.adoc', { safe: 'unsafe', logger: new asciidoctor.NullLogger() })
console.log(doc.getSourceLines())

Also, it's not necessary to define an attribute with a "boolean" value since in AsciiDoc the value will be text anyway. So, in your case you can just use :myvar:.

In the future, please direct usage question to the project chat at chat.asciidoctor.org. You can find more information about the support policy on the following page in the docs: docs.asciidoctor.org/about/support