Merge pull request #1820 from kxz/dtext-lists

Fixes for bulleted list rendering (#1803)
This commit is contained in:
Albert Yi
2013-07-01 18:13:52 -07:00
2 changed files with 22 additions and 7 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,10 +115,10 @@ class DText
html += "</#{elist}>"
end
end
html += "<li>#{content}</li>"
end
html += "<li>#{current_item}</li>"
while layout.any?
elist = layout.pop
html += "</#{elist}>"
@@ -187,7 +194,7 @@ class DText
else
""
end
when /\[code\](?!\])/
flags[:code] = true
'<pre>'
@@ -208,7 +215,7 @@ class DText
if stack.last == "expandable"
stack.pop
'</div></div>'
end
end
else
if flags[:code]

View File

@@ -100,7 +100,7 @@ class DTextTest < ActiveSupport::TestCase
def test_auto_urls_in_parentheses
assert_equal('<p>a (<a href="http://test.com">http://test.com</a>) b</p>', p('a (http://test.com) b'))
end
def test_old_syle_links
assert_equal('<p><a href="http://test.com">test</a></p>', p('"test":http://test.com'))
end
@@ -125,6 +125,14 @@ class DTextTest < ActiveSupport::TestCase
assert_equal('<ul><li><a href="/posts/1">post #1</a></li></ul>', p("* post #1").gsub(/\n/, ""))
end
def test_lists_not_preceded_by_newline
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
assert_equal('<p><a href="/posts?tags=tag">tag</a></p>', p("{{tag}}"))
end