Skip to content

Commit

Permalink
resolves asciidoctor#3693 don't break nested dlist with attached bloc…
Browse files Browse the repository at this point in the history
…k if offset from parent list by empty line
  • Loading branch information
mojavelinux committed Nov 5, 2023
1 parent 87e75f3 commit db8027f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Expand Up @@ -68,6 +68,7 @@ Improvements::

Bug Fixes::

* Don't break nested dlist with attached block if offset from parent list by empty line (#3693)
* Preserve paragraph breaks in normal table cell in manpage output (#4481)
* Escape spaces in include target (using inline passthrough) when generating link from include directive (#4461)

Expand Down
12 changes: 8 additions & 4 deletions lib/asciidoctor/parser.rb
Expand Up @@ -44,6 +44,10 @@ class Parser

AuthorKeys = ::Set['author', 'authorinitials', 'firstname', 'middlename', 'lastname', 'email']

ListContinuationMarker = ::Module.new

ListContinuation = ::String.new.extend ListContinuationMarker

# Internal: A Hash mapping horizontal alignment abbreviations to alignments
# that can be applied to a table cell (or to all cells in a column)
TableCellHorzAlignments = {
Expand Down Expand Up @@ -1419,11 +1423,11 @@ def self.read_lines_for_list_item reader, list_type, sibling_trait = nil, has_te

prev_line = buffer.empty? ? nil : buffer[-1]

if prev_line == LIST_CONTINUATION
if prev_line == LIST_CONTINUATION || ListContinuationMarker === prev_line
if continuation == :inactive
continuation = :active
has_text = true
buffer[-1] = '' unless within_nested_list
buffer[-1] = ListContinuation unless within_nested_list
end

# dealing with adjacent list continuations (which is really a syntax error)
Expand Down Expand Up @@ -1539,7 +1543,7 @@ def self.read_lines_for_list_item reader, list_type, sibling_trait = nil, has_te
buffer << this_line
has_text = true
end
elsif this_line == LIST_CONTINUATION
elsif this_line == LIST_CONTINUATION || ListContinuationMarker === this_line
has_text = true
buffer << this_line
else
Expand All @@ -1560,7 +1564,7 @@ def self.read_lines_for_list_item reader, list_type, sibling_trait = nil, has_te

reader.unshift_line this_line if this_line

buffer[detached_continuation] = '' if detached_continuation
buffer[detached_continuation] = ListContinuation if detached_continuation

until buffer.empty?
# strip trailing blank lines to prevent empty blocks
Expand Down
18 changes: 18 additions & 0 deletions test/lists_test.rb
Expand Up @@ -3077,6 +3077,24 @@
assert_xpath '//dl//dl/dt[normalize-space(text()) = "label1"]', output, 1
assert_xpath '//dl//dl/dt/following-sibling::dd/p[text() = "detail1"]', output, 1
end

test 'nested dlist with attached block offset by empty line' do
input = <<~'EOS'
category::
term 1:::
+
--
def 1
--
EOS
output = convert_string_to_embedded input
assert_xpath '//dl', output, 2
assert_xpath '//dl//dl', output, 1
assert_xpath '(//dl)[1]/dt[1][normalize-space(text()) = "category"]', output, 1
assert_xpath '(//dl)[1]//dl/dt[1][normalize-space(text()) = "term 1"]', output, 1
assert_xpath '(//dl)[1]//dl/dt[1]/following-sibling::dd//p[starts-with(text(), "def 1")]', output, 1
end
end

context 'Special lists' do
Expand Down

0 comments on commit db8027f

Please sign in to comment.