Defect #5445 » toclinks.diff
lib/redmine/wiki_formatting/textile/formatter.rb (working copy) | ||
---|---|---|
37 | 37 |
@toc = [] |
38 | 38 |
super(*RULES).to_s |
39 | 39 |
end |
40 |
|
|
40 |
|
|
41 |
def clear_toc_of_links! |
|
42 | ||
43 |
str = self.scan(/("[a-z0-9]+":(http|https):\/\/?(?:[-a-z0-9]+\.)+[a-z]{2,}(:[0-9]{1,5})?(\/*)?)/ix) |
|
44 |
size = str.size |
|
45 | ||
46 |
linkslist = Array.new(size) |
|
47 |
linkslist.map! { Array.new(1) } |
|
48 | ||
49 |
i = 0 |
|
50 | ||
51 |
str.each do |t| |
|
52 |
linkslist[i][0] = t[0].to_s |
|
53 |
tmpstr = linkslist[i].to_s |
|
54 |
tmpstr.delete! '"' |
|
55 |
tmpstr.delete! ":" |
|
56 |
linkstr = tmpstr.scan(/((http|https):?\/\/?(?:[-a-z0-9]+\.)+[a-z]{2,}(:[0-9]{1,5})?(\/*)?)/ix) |
|
57 |
delstr = linkstr[0][0].to_s |
|
58 |
tmpstr.gsub!(delstr, '') |
|
59 |
linkslist[i][1] = tmpstr |
|
60 |
self.gsub!(linkslist[i][0], linkslist[i][1]) |
|
61 |
i = i + 1 |
|
62 |
end |
|
63 |
self.to_s |
|
64 |
end |
|
65 |
|
|
41 | 66 |
private |
42 | 67 |
|
43 | 68 |
# Patch for RedCloth. Fixed in RedCloth r128 but _why hasn't released it yet. |
... | ... | |
85 | 110 |
alias :textile_h1 :textile_p_withtoc |
86 | 111 |
alias :textile_h2 :textile_p_withtoc |
87 | 112 |
alias :textile_h3 :textile_p_withtoc |
88 |
|
|
113 | ||
89 | 114 |
def inline_toc(text) |
90 | 115 |
text.gsub!(/<p>\{\{([<>]?)toc\}\}<\/p>/i) do |
91 | 116 |
div_class = 'toc' |
... | ... | |
94 | 119 |
out = "<ul class=\"#{div_class}\">" |
95 | 120 |
@toc.each do |heading| |
96 | 121 |
level, anchor, toc_item = heading |
122 |
toc_item.clear_toc_of_links! |
|
97 | 123 |
out << "<li class=\"heading#{level}\"><a href=\"##{anchor}\">#{toc_item}</a></li>\n" |
98 | 124 |
end |
99 | 125 |
out << '</ul>' |