diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-07-28 17:08:16 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-07-28 17:08:16 +0000 |
commit | 2dbc3d294364b59fb0360e15185894ca657e4ddd (patch) | |
tree | d89fd1fc8bb55b43277000e69b591b10f4849770 /lib/redmine/wiki_formatting.rb | |
parent | b20281f1515675813ade9e1284c39fd00d261365 (diff) | |
download | redmine-2dbc3d294364b59fb0360e15185894ca657e4ddd.tar.gz redmine-2dbc3d294364b59fb0360e15185894ca657e4ddd.zip |
Adds Trac-Like anchors on wiki headings (#1647).
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1705 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib/redmine/wiki_formatting.rb')
-rw-r--r-- | lib/redmine/wiki_formatting.rb | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/lib/redmine/wiki_formatting.rb b/lib/redmine/wiki_formatting.rb index 11ec6803a..8c18d547f 100644 --- a/lib/redmine/wiki_formatting.rb +++ b/lib/redmine/wiki_formatting.rb @@ -65,10 +65,22 @@ module Redmine # Patch to add 'table of content' support to RedCloth def textile_p_withtoc(tag, atts, cite, content) - if tag =~ /^h(\d)$/ - @toc << [$1.to_i, content] + # removes wiki links from the item + toc_item = content.gsub(/(\[\[|\]\])/, '') + # removes styles + # eg. %{color:red}Triggers% => Triggers + toc_item.gsub! %r[%\{[^\}]*\}([^%]+)%], '\\1' + + # replaces non word caracters by dashes + anchor = toc_item.gsub(%r{[^\w\s\-]}, '').gsub(%r{\s+(\-+\s*)?}, '-') + + unless anchor.blank? + if tag =~ /^h(\d)$/ + @toc << [$1.to_i, anchor, toc_item] + end + atts << " id=\"#{anchor}\"" + content = content + "<a href=\"##{anchor}\" class=\"wiki-anchor\">¶</a>" end - content = "<a name=\"#{@toc.length}\" class=\"wiki-page\"></a>" + content textile_p(tag, atts, cite, content) end @@ -82,13 +94,9 @@ module Redmine div_class << ' right' if $1 == '>' div_class << ' left' if $1 == '<' out = "<ul class=\"#{div_class}\">" - @toc.each_with_index do |heading, index| - # remove wiki links from the item - toc_item = heading.last.gsub(/(\[\[|\]\])/, '') - # remove styles - # eg. %{color:red}Triggers% => Triggers - toc_item.gsub! %r[%\{[^\}]*\}([^%]+)%], '\\1' - out << "<li class=\"heading#{heading.first}\"><a href=\"##{index+1}\">#{toc_item}</a></li>\n" + @toc.each do |heading| + level, anchor, toc_item = heading + out << "<li class=\"heading#{level}\"><a href=\"##{anchor}\">#{toc_item}</a></li>\n" end out << '</ul>' out |