Merge pull request #638 from ahus1

* gh-638:
  Polish "Prevent unwanted incrementing of section number in operation macro"
  Prevent unwanted incrementing of section number in operation macro

Closes gh-638
This commit is contained in:
Andy Wilkinson
2019-09-19 11:11:22 +01:00
3 changed files with 17 additions and 6 deletions

View File

@@ -48,9 +48,15 @@ class OperationBlockMacro < Asciidoctor::Extensions::BlockMacroProcessor
def add_blocks(content, doc, parent)
options = { safe: doc.options[:safe], attributes: doc.attributes }
fragment = Asciidoctor.load content, options
# use a template to get the correct sectname and level for blocks to append
template = create_section(parent, '', {})
fragment.blocks.each do |b|
b.parent = parent
b.level += parent.level
# might be a standard block and no section in case of 'No snippets were found for operation'
if b.respond_to?(:sectname)
b.sectname = template.sectname
end
b.level = template.level
parent << b
end
parent.find_by.each do |b|

View File

@@ -117,9 +117,8 @@ public abstract class AbstractOperationBlockMacroTests {
@Test
public void includeSnippetInSection() throws Exception {
String result = this.asciidoctor.convert(
"= A\n\nAlpha\n\n== B\n\nBravo\n\n" + "operation::some-operation[snippets='curl-request']",
this.options);
String result = this.asciidoctor.convert("= A\n:doctype: book\n:sectnums:\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"));
}

View File

@@ -6,18 +6,24 @@
</div>
</div>
<div class="sect1">
<h2 id="_b">B</h2>
<h2 id="_b">1. B</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Bravo</p>
</div>
<div class="sect2">
<h3 id="_b_curl_request">Curl request</h3>
<h3 id="_b_curl_request">1.1. Curl request</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-bash" data-lang="bash">$ curl 'http://localhost:8080/' -i</code></pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_c">2. C</h2>
<div class="sectionbody">
</div>
</div>