Skip to content

Commit 1d91136

Browse files
ahus1wilkinsona
authored andcommitted
Prevent unwanted incrementing of section number in operation macro
See gh-638
1 parent ae59baf commit 1d91136

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

spring-restdocs-asciidoctor-support/src/main/resources/extensions/operation_block_macro.rb

+7-1
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,15 @@ def do_read_snippets(snippets, parent, operation, snippet_titles)
4848
def add_blocks(content, doc, parent)
4949
options = { safe: doc.options[:safe], attributes: doc.attributes }
5050
fragment = Asciidoctor.load content, options
51+
# use a template to get the correct sectname and level for blocks to append
52+
template = create_section(parent, '', {})
5153
fragment.blocks.each do |b|
5254
b.parent = parent
53-
b.level += parent.level
55+
# might be a standard block and no section in case of 'No snippets were found for operation'
56+
if b.respond_to?(:sectname)
57+
b.sectname = template.sectname
58+
end
59+
b.level = template.level
5460
parent << b
5561
end
5662
parent.find_by.each do |b|

spring-restdocs-asciidoctor/src/test/java/org/springframework/restdocs/asciidoctor/AbstractOperationBlockMacroTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public void tableSnippetIncludeWithPdfBackend() throws Exception {
118118
@Test
119119
public void includeSnippetInSection() throws Exception {
120120
String result = this.asciidoctor.convert(
121-
"= A\n\nAlpha\n\n== B\n\nBravo\n\n" + "operation::some-operation[snippets='curl-request']",
121+
"= 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",
122122
this.options);
123123
assertThat(result).isEqualTo(getExpectedContentFromFile("snippet-in-section"));
124124
}

spring-restdocs-asciidoctor/src/test/resources/operations/snippet-in-section.html

+8-2
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,24 @@
66
</div>
77
</div>
88
<div class="sect1">
9-
<h2 id="_b">B</h2>
9+
<h2 id="_b">1. B</h2>
1010
<div class="sectionbody">
1111
<div class="paragraph">
1212
<p>Bravo</p>
1313
</div>
1414
<div class="sect2">
15-
<h3 id="_b_curl_request">Curl request</h3>
15+
<h3 id="_b_curl_request">1.1. Curl request</h3>
1616
<div class="listingblock">
1717
<div class="content">
1818
<pre class="highlight"><code class="language-bash" data-lang="bash">$ curl 'http://localhost:8080/' -i</code></pre>
1919
</div>
2020
</div>
2121
</div>
22+
</div>
23+
</div>
24+
<div class="sect1">
25+
<h2 id="_c">2. C</h2>
26+
<div class="sectionbody">
27+
2228
</div>
2329
</div>

0 commit comments

Comments
 (0)