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:
Kevin Xiwei Zheng
2013-07-01 21:07:23 -04:00
parent 817880012c
commit c6f79df22c
2 changed files with 16 additions and 9 deletions

View File

@@ -86,15 +86,22 @@ class DText
def self.parse_list(str, options = {})
html = ""
current_item = ""
layout = []
nest = 0
str.split(/\n/).each do |line|
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
content = parse_inline($2)
current_item = parse_inline($2)
else
content = parse_inline(line)
current_item += parse_inline(line)
end
if nest > layout.size
@@ -108,14 +115,10 @@ class DText
html += "</#{elist}>"
end
end
if nest > 0
html += "<li>#{content}</li>"
else
html += "<p>#{content}</p>"
end
end
html += "<li>#{current_item}</li>"
while layout.any?
elist = layout.pop
html += "</#{elist}>"

View File

@@ -126,7 +126,11 @@ class DTextTest < ActiveSupport::TestCase
end
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
def test_inline_tags