AsciidocFX
AsciidocFX copied to clipboard
Preview gets messed up due to leveloffset
When adding leveloffset
to the (last) include
the preview does not work correctly anymore.
You can reproduce it by creating a book from the template. And then changing the first include to:
include::preface.adoc[leveloffset=+1]
////
This results in the following preview:
As you can see, the title and the attributes appear in the preview. (For bigger documents the headers in the TOC are missing and/or have the wrong level. This is not shown here.) When exported to HTML the result is as expected.
Furthermore if the last include does not use a leveloffset
and contains a header, the preview works as expected.
In my case the following behavior is problematic:
When converting the text from the editor to HTML for the preview pane, every attribute defined in the document itself is also explicitly given as external attribute to Asciidoctor. See here: https://github.com/asciidocfx/AsciidocFX/blob/73175195cc68dd49484ad3e3e4e2fc17a687b14b/src/main/java/com/kodedu/engine/AsciidocAsciidoctorjConverter.java#L111-L125
If the line Attributes attributes = configBean.getAsciiDocAttributes(document.getAttributes());
is changed to Attributes attributes = configBean.getAsciiDocAttributes(Collections.emptyMap());
then the preview is rendered as expected.
Nevertheless Asciidoctor picks up the attributes defined in the document. See the following pictures. The TOC is moved to the right side, instead of the usual left, by defining it in the document header.
I am wondering why the above behavior was added in the first place? I guess that changing it like I proposed, will break another document, of which I am unaware of.
In getAsciiDocAttributes, we resolve the properties from 2 sources. From document and from AsciidocFX defined default attributes. Attributes are resolved in the following order.
- AsciidocFX defined attributes are added
- Document attributes are added
If we change the line as you defined, if there is a attribute defined in AsciidocFX's Settings will always override the user defined attribute. However, user defined attribute should always be prioritized.
If you put an empty file to the end of document, it should parse correctly. To be honest, I don't know what causes this issue.
The change here seems to fixing issue as well https://github.com/asciidocfx/AsciidocFX/commit/caf57af6dfe19179c431159dc7202a555504d525#diff-cea3c34c0764156781dc26cbc813b019daa7921c255b1aba9558e3dc0e1c8e44
Could you please check it ?
Thank you. I tested it with the above book example and I can not reproduce the error anymore.
This issue reappears in the 1.8.5 (06.05.2023) version. Although the behavior is slightly different now, as the picture are shown. (I have not looked at the changes yet.)
Proposed change brings more issues, that's why I reverted it back.
For a temporary solution you may add the following line to the end of the document
{empty} +