Project

General

Profile

Defect #5445 » toclinks.diff

Maksim Morozov, 2010-05-25 17:07

View differences:

lib/redmine/wiki_formatting/textile/formatter.rb (working copy)
@toc = []
super(*RULES).to_s
end
def clear_toc_of_links!
str = self.scan(/("[a-z0-9]+":(http|https):\/\/?(?:[-a-z0-9]+\.)+[a-z]{2,}(:[0-9]{1,5})?(\/*)?)/ix)
size = str.size
linkslist = Array.new(size)
linkslist.map! { Array.new(1) }
i = 0
str.each do |t|
linkslist[i][0] = t[0].to_s
tmpstr = linkslist[i].to_s
tmpstr.delete! '"'
tmpstr.delete! ":"
linkstr = tmpstr.scan(/((http|https):?\/\/?(?:[-a-z0-9]+\.)+[a-z]{2,}(:[0-9]{1,5})?(\/*)?)/ix)
delstr = linkstr[0][0].to_s
tmpstr.gsub!(delstr, '')
linkslist[i][1] = tmpstr
self.gsub!(linkslist[i][0], linkslist[i][1])
i = i + 1
end
self.to_s
end
private
# Patch for RedCloth. Fixed in RedCloth r128 but _why hasn't released it yet.
......
alias :textile_h1 :textile_p_withtoc
alias :textile_h2 :textile_p_withtoc
alias :textile_h3 :textile_p_withtoc
def inline_toc(text)
text.gsub!(/<p>\{\{([<>]?)toc\}\}<\/p>/i) do
div_class = 'toc'
......
out = "<ul class=\"#{div_class}\">"
@toc.each do |heading|
level, anchor, toc_item = heading
toc_item.clear_toc_of_links!
out << "<li class=\"heading#{level}\"><a href=\"##{anchor}\">#{toc_item}</a></li>\n"
end
out << '</ul>'
(3-3/5)