summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2024-02-20 04:29:29 -0700
committerGitHub <noreply@github.com>2024-02-20 04:29:29 -0700
commit0ef9bb00b7f17305396d0cb7640eb080929ccbc9 (patch)
treeec26e33c295c8af1afbd3943bc7f3cc3d72e84f7 /lib
parent5897ec073a37b1aba9f8240c7718ac970c4f47e5 (diff)
resolves #3693 don't break nested dlist with attached block if offset from parent list by empty line (PR #4512)
Diffstat (limited to 'lib')
-rw-r--r--lib/asciidoctor/parser.rb28
1 files changed, 18 insertions, 10 deletions
diff --git a/lib/asciidoctor/parser.rb b/lib/asciidoctor/parser.rb
index 8743b75e..bd1abad1 100644
--- a/lib/asciidoctor/parser.rb
+++ b/lib/asciidoctor/parser.rb
@@ -44,6 +44,12 @@ class Parser
AuthorKeys = ::Set['author', 'authorinitials', 'firstname', 'middlename', 'lastname', 'email']
+ ListContinuationMarker = ::Module.new
+
+ ListContinuationPlaceholder = ::String.new.extend ListContinuationMarker
+
+ ListContinuationString = (::String.new LIST_CONTINUATION).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 = {
@@ -1417,17 +1423,18 @@ class Parser
# the termination of the list
break if is_sibling_list_item? this_line, list_type, sibling_trait
+ this_line = ListContinuationString if this_line == LIST_CONTINUATION
prev_line = buffer.empty? ? nil : buffer[-1]
- if prev_line == LIST_CONTINUATION
+ if ListContinuationMarker === prev_line
if continuation == :inactive
continuation = :active
has_text = true
- buffer[-1] = '' unless within_nested_list
+ buffer[-1] = ListContinuationPlaceholder unless within_nested_list
end
# dealing with adjacent list continuations (which is really a syntax error)
- if this_line == LIST_CONTINUATION
+ if ListContinuationMarker === this_line
if continuation != :frozen
continuation = :frozen
buffer << this_line
@@ -1507,7 +1514,7 @@ class Parser
if this_line == LIST_CONTINUATION
detached_continuation = buffer.size
- buffer << this_line
+ buffer << ListContinuationString
elsif has_text # has_text only relevant for dlist, which is more greedy until it has text for an item; has_text is always true for all other lists
# in this block, we have to see whether we stay in the list
# TODO any way to combine this with the check after skipping blank lines?
@@ -1539,7 +1546,7 @@ class Parser
buffer << this_line
has_text = true
end
- elsif this_line == LIST_CONTINUATION
+ elsif ListContinuationMarker === this_line
has_text = true
buffer << this_line
else
@@ -1560,16 +1567,17 @@ class Parser
reader.unshift_line this_line if this_line
- buffer[detached_continuation] = '' if detached_continuation
+ buffer[detached_continuation] = ListContinuationPlaceholder if detached_continuation
until buffer.empty?
+ # drop optional trailing continuation
+ if ListContinuationMarker === (last_line = buffer[-1])
+ buffer.pop
+ break
# strip trailing blank lines to prevent empty blocks
- if (last_line = buffer[-1]).empty?
+ elsif last_line.empty?
buffer.pop
else
- # drop optional trailing continuation
- # (a blank line would have served the same purpose in the document)
- buffer.pop if last_line == LIST_CONTINUATION
break
end
end