Skip to content
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

resolves #4268 implicitly attach nested list that has block attribute lines to dlist entry #4439

Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ Bug Fixes::
* Don't allow target of include directive to start with a space (to distinguish it from a dlist item) or to end with a space
* Manify alt text of block image in manpage output (#4401)
* Adjust font size of term in horizontal dlist to match font size of term in regular dlist
* Implicitly attach nested list that starts with block attribute lines to dlist entry (#4268)

== 2.0.18 (2022-10-15) - @mojavelinux

Expand Down
23 changes: 19 additions & 4 deletions lib/asciidoctor/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1443,11 +1443,26 @@ def self.read_lines_for_list_item reader, list_type, sibling_trait = nil, has_te
# we're being more strict here about the terminator, but I think that's a good thing
buffer.concat reader.read_lines_until terminator: match.terminator, read_last_line: true, context: nil
continuation = :inactive
# technically BlockAttributeLineRx only breaks if ensuing line is not a list item
# which really means BlockAttributeLineRx only breaks if it's acting as a block delimiter
# FIXME to be AsciiDoc compliant, we shouldn't break if style in attribute line is "literal" (i.e., [literal])
# BlockAttributeLineRx only breaks dlist if ensuing line is not a list item
elsif dlist && continuation != :active && (BlockAttributeLineRx.match? this_line)
break
block_attribute_lines = [this_line]
while (next_line = reader.peek_line)
if is_delimited_block? next_line
interrupt = true
elsif next_line.empty? || ((next_line.start_with? '[') && (BlockAttributeLineRx.match? next_line))
block_attribute_lines << reader.read_line
next
elsif (AnyListRx.match? next_line) && !(is_sibling_list_item? next_line, list_type, sibling_trait)
buffer.concat block_attribute_lines
else # rubocop:disable Lint/DuplicateBranch
interrupt = true
end
break
end
if interrupt
reader.unshift_lines block_attribute_lines
break
end
elsif continuation == :active && !this_line.empty?
# literal paragraphs have special considerations (and this is one of
# two entry points into one)
Expand Down
83 changes: 83 additions & 0 deletions test/lists_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4155,6 +4155,89 @@
assert_xpath '//*[@class="dlist"]/following-sibling::*[@class="paragraph"]', output, 1
assert_xpath '//*[@class="dlist"]/following-sibling::*[@class="paragraph"]/p[text()="detached"]', output, 1
end

test 'block attribute lines above nested horizontal list does not break list' do
input = <<~'EOS'
Operating Systems::
[horizontal]
Linux::: Fedora
BSD::: OpenBSD

Cloud Providers::
PaaS::: OpenShift
IaaS::: AWS
EOS

output = convert_string_to_embedded input
assert_xpath '//dl', output, 2
assert_xpath '/*[@class="dlist"]/dl', output, 1
assert_xpath '(//dl)[1]/dd', output, 2
assert_xpath '((//dl)[1]/dd)[1]//table', output, 1
assert_xpath '((//dl)[1]/dd)[2]//table', output, 0
end

test 'block attribute lines above nested list with style does not break list' do
input = <<~'EOS'
TODO List::
* get groceries
Grocery List::
[square]
* bread
* milk
* lettuce
EOS

output = convert_string_to_embedded input
assert_xpath '//dl', output, 1
assert_xpath '(//dl)[1]/dd', output, 2
assert_xpath '((//dl)[1]/dd)[2]//ul[@class="square"]', output, 1
end

test 'multiple block attribute lines above nested list does not break list' do
input = <<~'EOS'
Operating Systems::
[[variants]]
[horizontal]
Linux::: Fedora
BSD::: OpenBSD

Cloud Providers::
PaaS::: OpenShift
IaaS::: AWS
EOS

output = convert_string_to_embedded input
assert_xpath '//dl', output, 2
assert_xpath '/*[@class="dlist"]/dl', output, 1
assert_xpath '(//dl)[1]/dd', output, 2
assert_xpath '(//dl)[1]/dd/*[@id="variants"]', output, 1
assert_xpath '((//dl)[1]/dd)[1]//table', output, 1
assert_xpath '((//dl)[1]/dd)[2]//table', output, 0
end

test 'multiple block attribute lines separated by empty line above nested list does not break list' do
input = <<~'EOS'
Operating Systems::
[[variants]]

[horizontal]

Linux::: Fedora
BSD::: OpenBSD

Cloud Providers::
PaaS::: OpenShift
IaaS::: AWS
EOS

output = convert_string_to_embedded input
assert_xpath '//dl', output, 2
assert_xpath '/*[@class="dlist"]/dl', output, 1
assert_xpath '(//dl)[1]/dd', output, 2
assert_xpath '(//dl)[1]/dd/*[@id="variants"]', output, 1
assert_xpath '((//dl)[1]/dd)[1]//table', output, 1
assert_xpath '((//dl)[1]/dd)[2]//table', output, 0
end
end

context 'Item with text inline' do
Expand Down