@@ -65,10 +65,22 module Redmine | |||||
65 |
|
65 | |||
66 | # Patch to add 'table of content' support to RedCloth |
|
66 | # Patch to add 'table of content' support to RedCloth | |
67 | def textile_p_withtoc(tag, atts, cite, content) |
|
67 | def textile_p_withtoc(tag, atts, cite, content) | |
68 | if tag =~ /^h(\d)$/ |
|
68 | # removes wiki links from the item | |
69 | @toc << [$1.to_i, content] |
|
69 | toc_item = content.gsub(/(\[\[|\]\])/, '') | |
|
70 | # removes styles | |||
|
71 | # eg. %{color:red}Triggers% => Triggers | |||
|
72 | toc_item.gsub! %r[%\{[^\}]*\}([^%]+)%], '\\1' | |||
|
73 | ||||
|
74 | # replaces non word caracters by dashes | |||
|
75 | anchor = toc_item.gsub(%r{[^\w\s\-]}, '').gsub(%r{\s+(\-+\s*)?}, '-') | |||
|
76 | ||||
|
77 | unless anchor.blank? | |||
|
78 | if tag =~ /^h(\d)$/ | |||
|
79 | @toc << [$1.to_i, anchor, toc_item] | |||
|
80 | end | |||
|
81 | atts << " id=\"#{anchor}\"" | |||
|
82 | content = content + "<a href=\"##{anchor}\" class=\"wiki-anchor\">¶</a>" | |||
70 | end |
|
83 | end | |
71 | content = "<a name=\"#{@toc.length}\" class=\"wiki-page\"></a>" + content |
|
|||
72 | textile_p(tag, atts, cite, content) |
|
84 | textile_p(tag, atts, cite, content) | |
73 | end |
|
85 | end | |
74 |
|
86 | |||
@@ -82,13 +94,9 module Redmine | |||||
82 | div_class << ' right' if $1 == '>' |
|
94 | div_class << ' right' if $1 == '>' | |
83 | div_class << ' left' if $1 == '<' |
|
95 | div_class << ' left' if $1 == '<' | |
84 | out = "<ul class=\"#{div_class}\">" |
|
96 | out = "<ul class=\"#{div_class}\">" | |
85 |
@toc.each |
|
97 | @toc.each do |heading| | |
86 | # remove wiki links from the item |
|
98 | level, anchor, toc_item = heading | |
87 | toc_item = heading.last.gsub(/(\[\[|\]\])/, '') |
|
99 | out << "<li class=\"heading#{level}\"><a href=\"##{anchor}\">#{toc_item}</a></li>\n" | |
88 | # remove styles |
|
|||
89 | # eg. %{color:red}Triggers% => Triggers |
|
|||
90 | toc_item.gsub! %r[%\{[^\}]*\}([^%]+)%], '\\1' |
|
|||
91 | out << "<li class=\"heading#{heading.first}\"><a href=\"##{index+1}\">#{toc_item}</a></li>\n" |
|
|||
92 | end |
|
100 | end | |
93 | out << '</ul>' |
|
101 | out << '</ul>' | |
94 | out |
|
102 | out |
@@ -487,6 +487,10 div.wiki ul.toc a { | |||||
487 | } |
|
487 | } | |
488 | div.wiki ul.toc a:hover { color: #c61a1a; text-decoration: underline;} |
|
488 | div.wiki ul.toc a:hover { color: #c61a1a; text-decoration: underline;} | |
489 |
|
489 | |||
|
490 | a.wiki-anchor { display: none; margin-left: 6px; text-decoration: none; } | |||
|
491 | a.wiki-anchor:hover { color: #aaa !important; text-decoration: none; } | |||
|
492 | h1:hover a.wiki-anchor, h2:hover a.wiki-anchor, h3:hover a.wiki-anchor { display: inline; color: #ddd; } | |||
|
493 | ||||
490 | /***** My page layout *****/ |
|
494 | /***** My page layout *****/ | |
491 | .block-receiver { |
|
495 | .block-receiver { | |
492 | border:1px dashed #c0c0c0; |
|
496 | border:1px dashed #c0c0c0; |
@@ -215,10 +215,10 h1. Another title | |||||
215 | RAW |
|
215 | RAW | |
216 |
|
216 | |||
217 | expected = '<ul class="toc">' + |
|
217 | expected = '<ul class="toc">' + | |
218 |
'<li class="heading1"><a href="# |
|
218 | '<li class="heading1"><a href="#Title">Title</a></li>' + | |
219 |
'<li class="heading2"><a href="# |
|
219 | '<li class="heading2"><a href="#Subtitle">Subtitle</a></li>' + | |
220 |
'<li class="heading2"><a href="# |
|
220 | '<li class="heading2"><a href="#Subtitle-with-red-text">Subtitle with red text</a></li>' + | |
221 |
'<li class="heading1"><a href="# |
|
221 | '<li class="heading1"><a href="#Another-title">Another title</a></li>' + | |
222 | '</ul>' |
|
222 | '</ul>' | |
223 |
|
223 | |||
224 | assert textilizable(raw).gsub("\n", "").include?(expected) |
|
224 | assert textilizable(raw).gsub("\n", "").include?(expected) |
General Comments 0
You need to be logged in to leave comments.
Login now