@@ -85,6 +85,9 module Redmine | |||||
85 | @toc.each_with_index do |heading, index| |
|
85 | @toc.each_with_index do |heading, index| | |
86 | # remove wiki links from the item |
|
86 | # remove wiki links from the item | |
87 | toc_item = heading.last.gsub(/(\[\[|\]\])/, '') |
|
87 | toc_item = heading.last.gsub(/(\[\[|\]\])/, '') | |
|
88 | # remove styles | |||
|
89 | # eg. %{color:red}Triggers% => Triggers | |||
|
90 | toc_item.gsub! %r[%\{[^\}]*\}([^%]+)%], '\\1' | |||
88 | out << "<a href=\"##{index+1}\" class=\"heading#{heading.first}\">#{toc_item}</a>" |
|
91 | out << "<a href=\"##{index+1}\" class=\"heading#{heading.first}\">#{toc_item}</a>" | |
89 | end |
|
92 | end | |
90 | out << '</div>' |
|
93 | out << '</div>' |
@@ -183,6 +183,34 class ApplicationHelperTest < HelperTestCase | |||||
183 | assert_equal '<p>Dashes: ---</p>', textilizable('Dashes: ---') |
|
183 | assert_equal '<p>Dashes: ---</p>', textilizable('Dashes: ---') | |
184 | end |
|
184 | end | |
185 |
|
185 | |||
|
186 | def test_table_of_content | |||
|
187 | raw = <<-RAW | |||
|
188 | {{toc}} | |||
|
189 | ||||
|
190 | h1. Title | |||
|
191 | ||||
|
192 | Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas sed libero. | |||
|
193 | ||||
|
194 | h2. Subtitle | |||
|
195 | ||||
|
196 | Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor. | |||
|
197 | ||||
|
198 | h2. Subtitle with %{color:red}red text% | |||
|
199 | ||||
|
200 | h1. Another title | |||
|
201 | ||||
|
202 | RAW | |||
|
203 | ||||
|
204 | expected = '<div class="toc">' + | |||
|
205 | '<a href="#1" class="heading1">Title</a>' + | |||
|
206 | '<a href="#2" class="heading2">Subtitle</a>' + | |||
|
207 | '<a href="#3" class="heading2">Subtitle with red text</a>' + | |||
|
208 | '<a href="#4" class="heading1">Another title</a>' + | |||
|
209 | '</div>' | |||
|
210 | ||||
|
211 | assert textilizable(raw).include?(expected) | |||
|
212 | end | |||
|
213 | ||||
186 | def test_blockquote |
|
214 | def test_blockquote | |
187 | # orig raw text |
|
215 | # orig raw text | |
188 | raw = <<-RAW |
|
216 | raw = <<-RAW |
General Comments 0
You need to be logged in to leave comments.
Login now