]> source.dussan.org Git - redmine.git/commitdiff
Fixed: right-aligned table of contents (TOC) not working with markdown (#16236).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 21 Mar 2014 01:35:21 +0000 (01:35 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 21 Mar 2014 01:35:21 +0000 (01:35 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@12989 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/application_helper.rb
test/unit/helpers/application_helper_test.rb

index 363653cd832e34ceda3b781513cd0875e9156468..acb7ba9db877f4f066f06f3bf55a64179e70f2fc 100644 (file)
@@ -978,19 +978,20 @@ module ApplicationHelper
     end
   end
 
-  TOC_RE = /<p>\{\{([<>]?)toc\}\}<\/p>/i unless const_defined?(:TOC_RE)
+  TOC_RE = /<p>\{\{((<|&lt;)|(>|&gt;))?toc\}\}<\/p>/i unless const_defined?(:TOC_RE)
 
   # Renders the TOC with given headings
   def replace_toc(text, headings)
     text.gsub!(TOC_RE) do
+      left_align, right_align = $2, $3
       # Keep only the 4 first levels
       headings = headings.select{|level, anchor, item| level <= 4}
       if headings.empty?
         ''
       else
         div_class = 'toc'
-        div_class << ' right' if $1 == '>'
-        div_class << ' left' if $1 == '<'
+        div_class << ' right' if right_align
+        div_class << ' left' if left_align
         out = "<ul class=\"#{div_class}\"><li>"
         root = headings.map(&:first).min
         current = root
index f645f1a52d6e73aa5afc22e837ad4c9425eda8cd..b06936abcf8b3c8d2e7eacde36e54293f196d549 100644 (file)
@@ -1167,6 +1167,22 @@ RAW
     assert textilizable(raw).gsub("\n", "").include?(expected)
   end
 
+  def test_toc_with_textile_formatting_should_be_parsed
+    with_settings :text_formatting => 'textile' do
+      assert_select_in textilizable("{{toc}}\n\nh1. Heading"), 'ul.toc li', :text => 'Heading'
+      assert_select_in textilizable("{{<toc}}\n\nh1. Heading"), 'ul.toc.left li', :text => 'Heading'
+      assert_select_in textilizable("{{>toc}}\n\nh1. Heading"), 'ul.toc.right li', :text => 'Heading'
+    end
+  end
+
+  def test_toc_with_markdown_formatting_should_be_parsed
+    with_settings :text_formatting => 'markdown' do
+      assert_select_in textilizable("{{toc}}\n\n# Heading"), 'ul.toc li', :text => 'Heading'
+      assert_select_in textilizable("{{<toc}}\n\n# Heading"), 'ul.toc.left li', :text => 'Heading'
+      assert_select_in textilizable("{{>toc}}\n\n# Heading"), 'ul.toc.right li', :text => 'Heading'
+    end
+  end
+
   def test_section_edit_links
     raw = <<-RAW
 h1. Title