From: Jean-Philippe Lang Date: Sun, 9 Sep 2007 10:16:59 +0000 (+0000) Subject: Added automatic table of content support on wiki pages, based on h1., h2. and h3... X-Git-Tag: 0.6.0~164 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f3364b9dce6f13905e94252b732b203203cded96;p=redmine.git Added automatic table of content support on wiki pages, based on h1., h2. and h3. headings. To display the page TOC, insert a line with this tag: {{toc}} or {{ left aligned toc {{>toc}} => right aligned toc git-svn-id: http://redmine.rubyforge.org/svn/trunk@718 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/lib/redmine/wiki_formatting.rb b/lib/redmine/wiki_formatting.rb index e9f5eb749..2d26cabd2 100644 --- a/lib/redmine/wiki_formatting.rb +++ b/lib/redmine/wiki_formatting.rb @@ -7,14 +7,15 @@ module Redmine private class TextileFormatter < RedCloth - RULES = [:inline_auto_link, :inline_auto_mailto, :textile ] - + RULES = [:inline_auto_link, :inline_auto_mailto, :textile, :inline_toc] + def initialize(*args) super self.hard_breaks=true end def to_html + @toc = [] super(*RULES).to_s end @@ -41,6 +42,32 @@ module Redmine end end + # 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] + end + content = "" + content + textile_p(tag, atts, cite, content) + end + + alias :textile_h1 :textile_p_withtoc + alias :textile_h2 :textile_p_withtoc + alias :textile_h3 :textile_p_withtoc + + def inline_toc(text) + text.gsub!(/

\{\{(<>?)toc\}\}<\/p>/i) do + div_class = 'toc' + div_class << ' right' if $1 == '>' + out = "

" + @toc.each_with_index do |heading, index| + out << "#{heading.last}" + end + out << '
' + out + end + end + AUTO_LINK_RE = %r{ ( # leading text <\w+.*?>| # leading HTML tag, or diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 8f4a3ecdb..5b3e70246 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -619,7 +619,7 @@ div.wiki a { background-image: url(../images/external.png); } -div.wiki a.wiki-page, div.wiki a.issue, div.wiki a.changeset, div.wiki a.email { +div.wiki a.wiki-page, div.wiki a.issue, div.wiki a.changeset, div.wiki a.email, div.wiki div.toc a { padding-left: 0; background-image: none; } @@ -643,6 +643,34 @@ div.wiki pre { border: 1px solid #dadada; } +div.wiki div.toc { + background-color: #fdfed0; + border: 1px solid #dadada; + padding: 4px; + line-height: 1.1em; + margin-bottom: 12px; + float: left; + margin-right: 12px; +} + +div.wiki div.toc.right { + float: right; + margin-left: 12px; + margin-right: 0; +} + +div.wiki div.toc a { + display: block; + font-size: 0.9em; + font-weight: normal; + color: #606060; +} + +div.wiki div.toc a.heading2 { margin-left: 6px; } +div.wiki div.toc a.heading3 { margin-left: 12px; font-size: 0.8em; } + +div.wiki + .diff_out{ background: #fcc; }