Skip to content

Section title out of sequence warnings may be generated when using operation macro #628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ def read_snippets(snippets_dir, snippet_names, parent, operation,

def do_read_snippets(snippets, parent, operation, snippet_titles)
content = StringIO.new
section_level = parent.level + 1
section_id = parent.id
snippets.each do |snippet|
append_snippet_block(content, snippet, section_level, section_id,
append_snippet_block(content, snippet, section_id,
operation, snippet_titles)
end
content.string
Expand All @@ -51,11 +50,12 @@ def add_blocks(content, doc, parent)
fragment = Asciidoctor.load content, options
fragment.blocks.each do |b|
b.parent = parent
b.level += parent.level
parent << b
end
parent.find_by.each do |b|
b.parent = b.parent unless b.is_a? Asciidoctor::Document
end
b.parent = b.parent unless b.is_a? Asciidoctor::Document
end
end

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

def append_snippet_block(content, snippet, section_level, section_id,
def append_snippet_block(content, snippet, section_id,
operation, snippet_titles)
write_title content, snippet, section_level, section_id, snippet_titles
write_title content, snippet, section_id, snippet_titles
write_content content, snippet, operation
end

Expand All @@ -96,8 +96,8 @@ def write_content(content, snippet, operation)
end
end

def write_title(content, snippet, level, id, snippet_titles)
section_level = '=' * (level + 1)
def write_title(content, snippet, id, snippet_titles)
section_level = '=='
Copy link
Member

@wilkinsona wilkinsona Aug 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switch to hardcoding two = feels like it may cause a regression to me. For example, will it not now be wrong if the macro is used in a deeply nested section?

Copy link
Contributor Author

@ahus1 ahus1 Aug 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new line 53 will adjust the level of all top level blocks the moment they are inserted. This avoid the warning that would otherwise occur when starting with a section of a too high level, and avoid having a regression.

title = snippet_titles.title_for_snippet snippet
content.puts "[[#{id}_#{snippet.name.sub '-', '_'}]]"
content.puts "#{section_level} #{title}"
Expand Down Expand Up @@ -141,4 +141,4 @@ def title_for_snippet(snippet)
end
end
end
end
end