@@ -7,7 +7,7 module Redmine | |||
|
7 | 7 | private |
|
8 | 8 | |
|
9 | 9 | class TextileFormatter < RedCloth |
|
10 | RULES = [:inline_auto_link, :inline_auto_mailto, :textile ] | |
|
10 | RULES = [:inline_auto_link, :inline_auto_mailto, :textile, :inline_toc] | |
|
11 | 11 | |
|
12 | 12 | def initialize(*args) |
|
13 | 13 | super |
@@ -15,6 +15,7 module Redmine | |||
|
15 | 15 | end |
|
16 | 16 | |
|
17 | 17 | def to_html |
|
18 | @toc = [] | |
|
18 | 19 | super(*RULES).to_s |
|
19 | 20 | end |
|
20 | 21 | |
@@ -41,6 +42,32 module Redmine | |||
|
41 | 42 | end |
|
42 | 43 | end |
|
43 | 44 | |
|
45 | # Patch to add 'table of content' support to RedCloth | |
|
46 | def textile_p_withtoc(tag, atts, cite, content) | |
|
47 | if tag =~ /^h(\d)$/ | |
|
48 | @toc << [$1.to_i, content] | |
|
49 | end | |
|
50 | content = "<a name=\"#{@toc.length}-#{content}\" class=\"wiki-page\"></a>" + content | |
|
51 | textile_p(tag, atts, cite, content) | |
|
52 | end | |
|
53 | ||
|
54 | alias :textile_h1 :textile_p_withtoc | |
|
55 | alias :textile_h2 :textile_p_withtoc | |
|
56 | alias :textile_h3 :textile_p_withtoc | |
|
57 | ||
|
58 | def inline_toc(text) | |
|
59 | text.gsub!(/<p>\{\{(<>?)toc\}\}<\/p>/i) do | |
|
60 | div_class = 'toc' | |
|
61 | div_class << ' right' if $1 == '>' | |
|
62 | out = "<div class=\"#{div_class}\">" | |
|
63 | @toc.each_with_index do |heading, index| | |
|
64 | out << "<a href=\"##{index+1}-#{heading.last}\" class=\"heading#{heading.first}\">#{heading.last}</a>" | |
|
65 | end | |
|
66 | out << '</div>' | |
|
67 | out | |
|
68 | end | |
|
69 | end | |
|
70 | ||
|
44 | 71 | AUTO_LINK_RE = %r{ |
|
45 | 72 | ( # leading text |
|
46 | 73 | <\w+.*?>| # leading HTML tag, or |
@@ -619,7 +619,7 div.wiki a { | |||
|
619 | 619 | background-image: url(../images/external.png); |
|
620 | 620 | } |
|
621 | 621 | |
|
622 | div.wiki a.wiki-page, div.wiki a.issue, div.wiki a.changeset, div.wiki a.email { | |
|
622 | div.wiki a.wiki-page, div.wiki a.issue, div.wiki a.changeset, div.wiki a.email, div.wiki div.toc a { | |
|
623 | 623 | padding-left: 0; |
|
624 | 624 | background-image: none; |
|
625 | 625 | } |
@@ -643,6 +643,34 div.wiki pre { | |||
|
643 | 643 | border: 1px solid #dadada; |
|
644 | 644 | } |
|
645 | 645 | |
|
646 | div.wiki div.toc { | |
|
647 | background-color: #fdfed0; | |
|
648 | border: 1px solid #dadada; | |
|
649 | padding: 4px; | |
|
650 | line-height: 1.1em; | |
|
651 | margin-bottom: 12px; | |
|
652 | float: left; | |
|
653 | margin-right: 12px; | |
|
654 | } | |
|
655 | ||
|
656 | div.wiki div.toc.right { | |
|
657 | float: right; | |
|
658 | margin-left: 12px; | |
|
659 | margin-right: 0; | |
|
660 | } | |
|
661 | ||
|
662 | div.wiki div.toc a { | |
|
663 | display: block; | |
|
664 | font-size: 0.9em; | |
|
665 | font-weight: normal; | |
|
666 | color: #606060; | |
|
667 | } | |
|
668 | ||
|
669 | div.wiki div.toc a.heading2 { margin-left: 6px; } | |
|
670 | div.wiki div.toc a.heading3 { margin-left: 12px; font-size: 0.8em; } | |
|
671 | ||
|
672 | div.wiki | |
|
673 | ||
|
646 | 674 | .diff_out{ |
|
647 | 675 | background: #fcc; |
|
648 | 676 | } |
General Comments 0
You need to be logged in to leave comments.
Login now