def self.read_lines_for_list_item(reader, list_type, sibling_trait = nil, has_text = true)
buffer = []
continuation = :inactive
within_nested_list = false
detached_continuation = nil
while reader.has_more_lines?
this_line = reader.read_line
break if is_sibling_list_item?(this_line, list_type, sibling_trait)
prev_line = buffer.empty? ? nil : buffer[-1]
if prev_line == LIST_CONTINUATION
if continuation == :inactive
continuation = :active
has_text = true
buffer[-1] = '' unless within_nested_list
end
if this_line == LIST_CONTINUATION
if continuation != :frozen
continuation = :frozen
buffer << this_line
end
this_line = nil
next
end
end
if (match = is_delimited_block?(this_line, true))
if continuation == :active
buffer << this_line
buffer.concat reader.read_lines_until(:terminator => match.terminator, :read_last_line => true)
continuation = :inactive
else
break
end
elsif list_type == :dlist && continuation != :active && (BlockAttributeLineRx.match? this_line)
break
else
if continuation == :active && !this_line.empty?
if LiteralParagraphRx.match? this_line
reader.unshift_line this_line
buffer.concat reader.read_lines_until(
:preserve_last_line => true,
:break_on_blank_lines => true,
:break_on_list_continuation => true) {|line|
list_type == :dlist && is_sibling_list_item?(line, list_type, sibling_trait)
}
continuation = :inactive
elsif (BlockTitleRx.match? this_line) || (BlockAttributeLineRx.match? this_line) || (AttributeEntryRx.match? this_line)
buffer << this_line
else
if nested_list_type = (within_nested_list ? [:dlist] : NESTABLE_LIST_CONTEXTS).find {|ctx| ListRxMap[ctx].match? this_line }
within_nested_list = true
if nested_list_type == :dlist && $3.nil_or_empty?
has_text = false
end
end
buffer << this_line
continuation = :inactive
end
elsif prev_line && prev_line.empty?
if this_line.empty?
break unless (this_line = reader.skip_blank_lines && reader.read_line)
break if is_sibling_list_item? this_line, list_type, sibling_trait
end
if this_line == LIST_CONTINUATION
detached_continuation = buffer.size
buffer << this_line
else
if has_text
if is_sibling_list_item?(this_line, list_type, sibling_trait)
break
elsif nested_list_type = NESTABLE_LIST_CONTEXTS.find {|ctx| ListRxMap[ctx] =~ this_line }
buffer << this_line
within_nested_list = true
if nested_list_type == :dlist && $3.nil_or_empty?
has_text = false
end
elsif LiteralParagraphRx.match? this_line
reader.unshift_line this_line
buffer.concat reader.read_lines_until(
:preserve_last_line => true,
:break_on_blank_lines => true,
:break_on_list_continuation => true) {|line|
list_type == :dlist && is_sibling_list_item?(line, list_type, sibling_trait)
}
else
break
end
else
buffer.pop unless within_nested_list
buffer << this_line
has_text = true
end
end
else
has_text = true if !this_line.empty?
if nested_list_type = (within_nested_list ? [:dlist] : NESTABLE_LIST_CONTEXTS).find {|ctx| ListRxMap[ctx] =~ this_line }
within_nested_list = true
if nested_list_type == :dlist && $3.nil_or_empty?
has_text = false
end
end
buffer << this_line
end
end
this_line = nil
end
reader.unshift_line this_line if this_line
if detached_continuation
buffer.delete_at detached_continuation
end
buffer.pop while !buffer.empty? && buffer[-1].empty?
buffer.pop if !buffer.empty? && buffer[-1] == LIST_CONTINUATION
buffer
end