More complete fix for #1803
When a list is prefixed by more than one non-list line, output those prefix lines as part of the same paragraph, not as separate ones. Treat other lines not beginning with a "*" as continuations of the previous list item.
This commit is contained in:
@@ -86,15 +86,22 @@ class DText
|
|||||||
|
|
||||||
def self.parse_list(str, options = {})
|
def self.parse_list(str, options = {})
|
||||||
html = ""
|
html = ""
|
||||||
|
current_item = ""
|
||||||
layout = []
|
layout = []
|
||||||
nest = 0
|
nest = 0
|
||||||
|
|
||||||
str.split(/\n/).each do |line|
|
str.split(/\n/).each do |line|
|
||||||
if line =~ /^\s*(\*+) (.+)/
|
if line =~ /^\s*(\*+) (.+)/
|
||||||
|
if nest > 0
|
||||||
|
html += "<li>#{current_item}</li>"
|
||||||
|
elsif not current_item.strip.empty?
|
||||||
|
html += "<p>#{current_item}</p>"
|
||||||
|
end
|
||||||
|
|
||||||
nest = $1.size
|
nest = $1.size
|
||||||
content = parse_inline($2)
|
current_item = parse_inline($2)
|
||||||
else
|
else
|
||||||
content = parse_inline(line)
|
current_item += parse_inline(line)
|
||||||
end
|
end
|
||||||
|
|
||||||
if nest > layout.size
|
if nest > layout.size
|
||||||
@@ -108,14 +115,10 @@ class DText
|
|||||||
html += "</#{elist}>"
|
html += "</#{elist}>"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if nest > 0
|
|
||||||
html += "<li>#{content}</li>"
|
|
||||||
else
|
|
||||||
html += "<p>#{content}</p>"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
html += "<li>#{current_item}</li>"
|
||||||
|
|
||||||
while layout.any?
|
while layout.any?
|
||||||
elist = layout.pop
|
elist = layout.pop
|
||||||
html += "</#{elist}>"
|
html += "</#{elist}>"
|
||||||
|
|||||||
@@ -126,7 +126,11 @@ class DTextTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_lists_not_preceded_by_newline
|
def test_lists_not_preceded_by_newline
|
||||||
assert_equal('<p>a</p><ul><li>b</li><li>c</li></ul>', p("a\n* b\n* c").gsub(/\n/, ""))
|
assert_equal('<p>ab</p><ul><li>c</li><li>d</li></ul>', p("a\nb\n* c\n* d").gsub(/\n/, ""))
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_lists_with_multiline_items
|
||||||
|
assert_equal('<p>a</p><ul><li>bc</li><li>de</li></ul>', p("a\n* b\nc\n* d\ne").gsub(/\n/, ""))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_inline_tags
|
def test_inline_tags
|
||||||
|
|||||||
Reference in New Issue
Block a user