From 817880012c1a73fd4ba71e15299e08ff301b6458 Mon Sep 17 00:00:00 2001 From: Kevin Xiwei Zheng Date: Mon, 1 Jul 2013 20:47:00 -0400 Subject: [PATCH 1/2] Band-aid fix for bulleted list rendering (#1803) --- app/logical/d_text.rb | 10 +++++++--- test/unit/dtext_test.rb | 6 +++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/logical/d_text.rb b/app/logical/d_text.rb index 67bfe6298..fd776ba5b 100644 --- a/app/logical/d_text.rb +++ b/app/logical/d_text.rb @@ -109,7 +109,11 @@ class DText end end - html += "
  • #{content}
  • " + if nest > 0 + html += "
  • #{content}
  • " + else + html += "

    #{content}

    " + end end while layout.any? @@ -187,7 +191,7 @@ class DText else "" end - + when /\[code\](?!\])/ flags[:code] = true '
    '
    @@ -208,7 +212,7 @@ class DText
             if stack.last == "expandable"
               stack.pop
               ''
    -        end 
    +        end
     
           else
             if flags[:code]
    diff --git a/test/unit/dtext_test.rb b/test/unit/dtext_test.rb
    index aa6860e6b..f737446a6 100644
    --- a/test/unit/dtext_test.rb
    +++ b/test/unit/dtext_test.rb
    @@ -100,7 +100,7 @@ class DTextTest < ActiveSupport::TestCase
       def test_auto_urls_in_parentheses
         assert_equal('

    a (http://test.com) b

    ', p('a (http://test.com) b')) end - + def test_old_syle_links assert_equal('

    test

    ', p('"test":http://test.com')) end @@ -125,6 +125,10 @@ class DTextTest < ActiveSupport::TestCase assert_equal('', p("* post #1").gsub(/\n/, "")) end + def test_lists_not_preceded_by_newline + assert_equal('

    a

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

    tag

    ', p("{{tag}}")) end From c6f79df22c6c5d61a4525490ba94598031582261 Mon Sep 17 00:00:00 2001 From: Kevin Xiwei Zheng Date: Mon, 1 Jul 2013 21:07:23 -0400 Subject: [PATCH 2/2] 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

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

    ab

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

    a

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