Fix problem with operation block macro when using leveloffset

Previously, when a document had a leveloffset attribute this was
included in the attributes used when loading a snippet in the
operation block macro. This could lead to warnings about section
titles being out of sequence as the level used for the title did not
take the leveloffset into consideration.

This commit clones the documents attributes and removes any
leveloffset attribute before loading a snippet. This removes the
need for the leveloffset to be considered when loading a snippet
fragment. As before, the level of each block in the fragment loaded
from snippet is then set prior to adding the block to the main
document. This takes the leveloffset into consideration.

Closes gh-649
This commit is contained in:
Andy Wilkinson
2019-10-17 15:40:52 +01:00
parent 835f0d3a43
commit bb7aecbfe5
2 changed files with 18 additions and 1 deletions

View File

@@ -46,7 +46,8 @@ class OperationBlockMacro < Asciidoctor::Extensions::BlockMacroProcessor
end
def add_blocks(content, doc, parent)
options = { safe: doc.options[:safe], attributes: doc.attributes }
options = { safe: doc.options[:safe], attributes: doc.attributes.clone }
options[:attributes].delete 'leveloffset'
fragment = Asciidoctor.load content, options
# use a template to get the correct sectname and level for blocks to append
template = create_section(parent, '', {})

View File

@@ -122,6 +122,22 @@ public abstract class AbstractOperationBlockMacroTests {
assertThat(result).isEqualTo(getExpectedContentFromFile("snippet-in-section"));
}
@Test
public void includeSnippetInSectionWithAbsoluteLevelOffset() throws Exception {
String result = this.asciidoctor
.convert("= A\n:doctype: book\n:sectnums:\n:leveloffset: 1\n\nAlpha\n\n= B\n\nBravo\n\n"
+ "operation::some-operation[snippets='curl-request']\n\n= C\n", this.options);
assertThat(result).isEqualTo(getExpectedContentFromFile("snippet-in-section"));
}
@Test
public void includeSnippetInSectionWithRelativeLevelOffset() throws Exception {
String result = this.asciidoctor
.convert("= A\n:doctype: book\n:sectnums:\n:leveloffset: +1\n\nAlpha\n\n= B\n\nBravo\n\n"
+ "operation::some-operation[snippets='curl-request']\n\n= C\n", this.options);
assertThat(result).isEqualTo(getExpectedContentFromFile("snippet-in-section"));
}
@Test
public void includeSnippetInSectionWithPdfBackend() throws Exception {
File output = configurePdfOutput();