Merge pull request #1820 from kxz/dtext-lists
Fixes for bulleted list rendering (#1803)
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,10 +115,10 @@ class DText
|
|||||||
html += "</#{elist}>"
|
html += "</#{elist}>"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
html += "<li>#{content}</li>"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
html += "<li>#{current_item}</li>"
|
||||||
|
|
||||||
while layout.any?
|
while layout.any?
|
||||||
elist = layout.pop
|
elist = layout.pop
|
||||||
html += "</#{elist}>"
|
html += "</#{elist}>"
|
||||||
@@ -187,7 +194,7 @@ class DText
|
|||||||
else
|
else
|
||||||
""
|
""
|
||||||
end
|
end
|
||||||
|
|
||||||
when /\[code\](?!\])/
|
when /\[code\](?!\])/
|
||||||
flags[:code] = true
|
flags[:code] = true
|
||||||
'<pre>'
|
'<pre>'
|
||||||
@@ -208,7 +215,7 @@ class DText
|
|||||||
if stack.last == "expandable"
|
if stack.last == "expandable"
|
||||||
stack.pop
|
stack.pop
|
||||||
'</div></div>'
|
'</div></div>'
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
if flags[:code]
|
if flags[:code]
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ class DTextTest < ActiveSupport::TestCase
|
|||||||
def test_auto_urls_in_parentheses
|
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'))
|
assert_equal('<p>a (<a href="http://test.com">http://test.com</a>) b</p>', p('a (http://test.com) b'))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_old_syle_links
|
def test_old_syle_links
|
||||||
assert_equal('<p><a href="http://test.com">test</a></p>', p('"test":http://test.com'))
|
assert_equal('<p><a href="http://test.com">test</a></p>', p('"test":http://test.com'))
|
||||||
end
|
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/, ""))
|
assert_equal('<ul><li><a href="/posts/1">post #1</a></li></ul>', p("* post #1").gsub(/\n/, ""))
|
||||||
end
|
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
|
def test_inline_tags
|
||||||
assert_equal('<p><a href="/posts?tags=tag">tag</a></p>', p("{{tag}}"))
|
assert_equal('<p><a href="/posts?tags=tag">tag</a></p>', p("{{tag}}"))
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user