##// END OF EJS Templates
Merged r12989 and r12997 (#16236)....
Jean-Philippe Lang -
r12745:c5b52ec29fcb
parent child
Show More
@@ -978,19 +978,20 module ApplicationHelper
978 end
978 end
979 end
979 end
980
980
981 TOC_RE = /<p>\{\{([<>]?)toc\}\}<\/p>/i unless const_defined?(:TOC_RE)
981 TOC_RE = /<p>\{\{((<|&lt;)|(>|&gt;))?toc\}\}<\/p>/i unless const_defined?(:TOC_RE)
982
982
983 # Renders the TOC with given headings
983 # Renders the TOC with given headings
984 def replace_toc(text, headings)
984 def replace_toc(text, headings)
985 text.gsub!(TOC_RE) do
985 text.gsub!(TOC_RE) do
986 left_align, right_align = $2, $3
986 # Keep only the 4 first levels
987 # Keep only the 4 first levels
987 headings = headings.select{|level, anchor, item| level <= 4}
988 headings = headings.select{|level, anchor, item| level <= 4}
988 if headings.empty?
989 if headings.empty?
989 ''
990 ''
990 else
991 else
991 div_class = 'toc'
992 div_class = 'toc'
992 div_class << ' right' if $1 == '>'
993 div_class << ' right' if right_align
993 div_class << ' left' if $1 == '<'
994 div_class << ' left' if left_align
994 out = "<ul class=\"#{div_class}\"><li>"
995 out = "<ul class=\"#{div_class}\"><li>"
995 root = headings.map(&:first).min
996 root = headings.map(&:first).min
996 current = root
997 current = root
@@ -1167,6 +1167,24 RAW
1167 assert textilizable(raw).gsub("\n", "").include?(expected)
1167 assert textilizable(raw).gsub("\n", "").include?(expected)
1168 end
1168 end
1169
1169
1170 def test_toc_with_textile_formatting_should_be_parsed
1171 with_settings :text_formatting => 'textile' do
1172 assert_select_in textilizable("{{toc}}\n\nh1. Heading"), 'ul.toc li', :text => 'Heading'
1173 assert_select_in textilizable("{{<toc}}\n\nh1. Heading"), 'ul.toc.left li', :text => 'Heading'
1174 assert_select_in textilizable("{{>toc}}\n\nh1. Heading"), 'ul.toc.right li', :text => 'Heading'
1175 end
1176 end
1177
1178 if Object.const_defined?(:Redcarpet)
1179 def test_toc_with_markdown_formatting_should_be_parsed
1180 with_settings :text_formatting => 'markdown' do
1181 assert_select_in textilizable("{{toc}}\n\n# Heading"), 'ul.toc li', :text => 'Heading'
1182 assert_select_in textilizable("{{<toc}}\n\n# Heading"), 'ul.toc.left li', :text => 'Heading'
1183 assert_select_in textilizable("{{>toc}}\n\n# Heading"), 'ul.toc.right li', :text => 'Heading'
1184 end
1185 end
1186 end
1187
1170 def test_section_edit_links
1188 def test_section_edit_links
1171 raw = <<-RAW
1189 raw = <<-RAW
1172 h1. Title
1190 h1. Title
General Comments 0
You need to be logged in to leave comments. Login now