Skip to content

Commit b66c8b4

Browse files
ahus1wilkinsona
authored andcommitted
Avoid warnings when parsing AsciiDoc sub-content in Asciidoctor.load
Renderings with standard section depth first to avoid warnings that document starts with level 3 headings. Adjust block level when adding the content to the parent. See gh-628
1 parent 0e9f9fd commit b66c8b4

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@ def read_snippets(snippets_dir, snippet_names, parent, operation,
3737

3838
def do_read_snippets(snippets, parent, operation, snippet_titles)
3939
content = StringIO.new
40-
section_level = parent.level + 1
4140
section_id = parent.id
4241
snippets.each do |snippet|
43-
append_snippet_block(content, snippet, section_level, section_id,
42+
append_snippet_block(content, snippet, section_id,
4443
operation, snippet_titles)
4544
end
4645
content.string
@@ -51,11 +50,12 @@ def add_blocks(content, doc, parent)
5150
fragment = Asciidoctor.load content, options
5251
fragment.blocks.each do |b|
5352
b.parent = parent
53+
b.level += parent.level
5454
parent << b
5555
end
5656
parent.find_by.each do |b|
57-
b.parent = b.parent unless b.is_a? Asciidoctor::Document
58-
end
57+
b.parent = b.parent unless b.is_a? Asciidoctor::Document
58+
end
5959
end
6060

6161
def snippets_to_include(snippet_names, snippets_dir, operation)
@@ -78,9 +78,9 @@ def all_snippets(snippets_dir, operation)
7878
.map { |file| Snippet.new(File.join(operation_dir, file), file[0..-6]) }
7979
end
8080

81-
def append_snippet_block(content, snippet, section_level, section_id,
81+
def append_snippet_block(content, snippet, section_id,
8282
operation, snippet_titles)
83-
write_title content, snippet, section_level, section_id, snippet_titles
83+
write_title content, snippet, section_id, snippet_titles
8484
write_content content, snippet, operation
8585
end
8686

@@ -96,8 +96,8 @@ def write_content(content, snippet, operation)
9696
end
9797
end
9898

99-
def write_title(content, snippet, level, id, snippet_titles)
100-
section_level = '=' * (level + 1)
99+
def write_title(content, snippet, id, snippet_titles)
100+
section_level = '=='
101101
title = snippet_titles.title_for_snippet snippet
102102
content.puts "[[#{id}_#{snippet.name.sub '-', '_'}]]"
103103
content.puts "#{section_level} #{title}"
@@ -141,4 +141,4 @@ def title_for_snippet(snippet)
141141
end
142142
end
143143
end
144-
end
144+
end

0 commit comments

Comments
 (0)