From c6f79df22c6c5d61a4525490ba94598031582261 Mon Sep 17 00:00:00 2001 From: Kevin Xiwei Zheng Date: Mon, 1 Jul 2013 21:07:23 -0400 Subject: [PATCH] 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. --- app/logical/d_text.rb | 19 +++++++++++-------- test/unit/dtext_test.rb | 6 +++++- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/app/logical/d_text.rb b/app/logical/d_text.rb index fd776ba5b..8f024028f 100644 --- a/app/logical/d_text.rb +++ b/app/logical/d_text.rb @@ -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 += "
  • #{current_item}
  • " + elsif not current_item.strip.empty? + html += "

    #{current_item}

    " + 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 += "" end end - - if nest > 0 - html += "
  • #{content}
  • " - else - html += "

    #{content}

    " - end end + html += "
  • #{current_item}
  • " + while layout.any? elist = layout.pop html += "" diff --git a/test/unit/dtext_test.rb b/test/unit/dtext_test.rb index f737446a6..a407f2335 100644 --- a/test/unit/dtext_test.rb +++ b/test/unit/dtext_test.rb @@ -126,7 +126,11 @@ class DTextTest < ActiveSupport::TestCase end def test_lists_not_preceded_by_newline - assert_equal('

    a

    ', p("a\n* b\n* c").gsub(/\n/, "")) + assert_equal('

    ab

    ', p("a\nb\n* c\n* d").gsub(/\n/, "")) + end + + def test_lists_with_multiline_items + assert_equal('

    a

    ', p("a\n* b\nc\n* d\ne").gsub(/\n/, "")) end def test_inline_tags