diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2010-11-06 18:52:07 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2010-11-06 18:52:07 +0000 |
commit | 7f9d2b080416132e0357bf3b95f6fa60082ba10b (patch) | |
tree | 0ded3e536a5361106df0f0af8e619b2be45b6e63 /app/helpers/application_helper.rb | |
parent | 024ff96ee27aa7e61ceec25a351f6800461d5cf3 (diff) | |
download | redmine-7f9d2b080416132e0357bf3b95f6fa60082ba10b.tar.gz redmine-7f9d2b080416132e0357bf3b95f6fa60082ba10b.zip |
Render TOC as nested lists (#1857).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4377 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/helpers/application_helper.rb')
-rw-r--r-- | app/helpers/application_helper.rb | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 0e4b0a8c3..b42960ec0 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -682,7 +682,7 @@ module ApplicationHelper def parse_headings(text, project, obj, attr, only_path, options) headings = [] text.gsub!(HEADING_RE) do - level, attrs, content = $1, $2, $3 + level, attrs, content = $1.to_i, $2, $3 item = strip_tags(content).strip anchor = item.gsub(%r{[^\w\s\-]}, '').gsub(%r{\s+(\-+\s*)?}, '-') headings << [level, anchor, item] @@ -696,12 +696,24 @@ module ApplicationHelper div_class = 'toc' div_class << ' right' if $1 == '>' div_class << ' left' if $1 == '<' - out = "<ul class=\"#{div_class}\">" + out = "<ul class=\"#{div_class}\"><li>" + root = headings.map(&:first).min + current = root + started = false headings.each do |level, anchor, item| - out << "<li class=\"heading#{level}\"><a href=\"##{anchor}\">#{item}</a></li>\n" + if level > current + out << '<ul><li>' * (level - current) + elsif level < current + out << "</li></ul>\n" * (current - level) + "</li><li>" + elsif started + out << '</li><li>' + end + out << "<a href=\"##{anchor}\">#{item}</a>" + current = level + started = true end - out << '</ul>' - out + out << '</li></ul>' * (current - root) + out << '</li></ul>' end end end |