@@ -978,19 +978,20 module ApplicationHelper | |||||
978 | end |
|
978 | end | |
979 | end |
|
979 | end | |
980 |
|
980 | |||
981 |
TOC_RE = /<p>\{\{( |
|
981 | TOC_RE = /<p>\{\{((<|<)|(>|>))?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 |
|
993 | div_class << ' right' if right_align | |
993 |
div_class << ' left' if |
|
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,22 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 | def test_toc_with_markdown_formatting_should_be_parsed | |||
|
1179 | with_settings :text_formatting => 'markdown' do | |||
|
1180 | assert_select_in textilizable("{{toc}}\n\n# Heading"), 'ul.toc li', :text => 'Heading' | |||
|
1181 | assert_select_in textilizable("{{<toc}}\n\n# Heading"), 'ul.toc.left li', :text => 'Heading' | |||
|
1182 | assert_select_in textilizable("{{>toc}}\n\n# Heading"), 'ul.toc.right li', :text => 'Heading' | |||
|
1183 | end | |||
|
1184 | end | |||
|
1185 | ||||
1170 | def test_section_edit_links |
|
1186 | def test_section_edit_links | |
1171 | raw = <<-RAW |
|
1187 | raw = <<-RAW | |
1172 | h1. Title |
|
1188 | h1. Title |
General Comments 0
You need to be logged in to leave comments.
Login now