@@ -978,19 +978,20 module ApplicationHelper | |||
|
978 | 978 | end |
|
979 | 979 | end |
|
980 | 980 | |
|
981 |
TOC_RE = /<p>\{\{( |
|
|
981 | TOC_RE = /<p>\{\{((<|<)|(>|>))?toc\}\}<\/p>/i unless const_defined?(:TOC_RE) | |
|
982 | 982 | |
|
983 | 983 | # Renders the TOC with given headings |
|
984 | 984 | def replace_toc(text, headings) |
|
985 | 985 | text.gsub!(TOC_RE) do |
|
986 | left_align, right_align = $2, $3 | |
|
986 | 987 | # Keep only the 4 first levels |
|
987 | 988 | headings = headings.select{|level, anchor, item| level <= 4} |
|
988 | 989 | if headings.empty? |
|
989 | 990 | '' |
|
990 | 991 | else |
|
991 | 992 | div_class = 'toc' |
|
992 |
div_class << ' right' if |
|
|
993 |
div_class << ' left' if |
|
|
993 | div_class << ' right' if right_align | |
|
994 | div_class << ' left' if left_align | |
|
994 | 995 | out = "<ul class=\"#{div_class}\"><li>" |
|
995 | 996 | root = headings.map(&:first).min |
|
996 | 997 | current = root |
@@ -1167,6 +1167,24 RAW | |||
|
1167 | 1167 | assert textilizable(raw).gsub("\n", "").include?(expected) |
|
1168 | 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 | 1188 | def test_section_edit_links |
|
1171 | 1189 | raw = <<-RAW |
|
1172 | 1190 | h1. Title |
General Comments 0
You need to be logged in to leave comments.
Login now