Create section in block macro
Posted by
dalai on
URL: https://discuss.asciidoctor.org/Create-section-in-block-macro-tp8127.html
I want to add a section using a macro. The problem is when I don't want it directly under the parent. My code is based on
https://discuss.asciidoctor.org/How-to-generate-sections-in-extension-tp2142p2236.htmlAssuming a document of this form:
== Chapter 1
=== Section 1.1
sample::[]
With the following macro it works as expected and the added section gets the number 1.1.1:
block_macro do
named :sample
process do |parent, target, attrs|
sect = create_section parent, "Added Section", { }
parent << sect
nil
end
end
If I set the level to 2 though the number is still 1.1.1 instead of 1.2. If I set the level to 1, the section number is 1 instead of 2. In all cases the styling is correct, just the numbering is wrong.
I also tried to add it to the parent.parent or the parent.parent.parent. In that case, it seems numbering and styling works correctly, but the added section is added before Section 1.1 or Chapter 1, respectively.
I understand that this use-case is not exactly foreseen for block macros. Is this a bug or is this a limitation of the extension? Is there an alternative or workaround? Should this be documented for the create_section method?
Thanks
Konstantinos