Fixed: partial toc when text contains pre tags (#7172).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4578 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
0025a66200
commit
af7006dff6
|
@ -449,12 +449,19 @@ module ApplicationHelper
|
||||||
only_path = options.delete(:only_path) == false ? false : true
|
only_path = options.delete(:only_path) == false ? false : true
|
||||||
|
|
||||||
text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text, :object => obj, :attribute => attr) { |macro, args| exec_macro(macro, obj, args) }
|
text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text, :object => obj, :attribute => attr) { |macro, args| exec_macro(macro, obj, args) }
|
||||||
|
|
||||||
parse_non_pre_blocks(text) do |text|
|
@parsed_headings = []
|
||||||
|
text = parse_non_pre_blocks(text) do |text|
|
||||||
[:parse_inline_attachments, :parse_wiki_links, :parse_redmine_links, :parse_headings].each do |method_name|
|
[:parse_inline_attachments, :parse_wiki_links, :parse_redmine_links, :parse_headings].each do |method_name|
|
||||||
send method_name, text, project, obj, attr, only_path, options
|
send method_name, text, project, obj, attr, only_path, options
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if @parsed_headings.any?
|
||||||
|
replace_toc(text, @parsed_headings)
|
||||||
|
end
|
||||||
|
|
||||||
|
text
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_non_pre_blocks(text)
|
def parse_non_pre_blocks(text)
|
||||||
|
@ -674,21 +681,26 @@ module ApplicationHelper
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
TOC_RE = /<p>\{\{([<>]?)toc\}\}<\/p>/i unless const_defined?(:TOC_RE)
|
|
||||||
HEADING_RE = /<h(1|2|3|4)( [^>]+)?>(.+?)<\/h(1|2|3|4)>/i unless const_defined?(:HEADING_RE)
|
HEADING_RE = /<h(1|2|3|4)( [^>]+)?>(.+?)<\/h(1|2|3|4)>/i unless const_defined?(:HEADING_RE)
|
||||||
|
|
||||||
# Headings and TOC
|
# Headings and TOC
|
||||||
# Adds ids and links to headings and renders the TOC if needed unless options[:headings] is set to false
|
# Adds ids and links to headings unless options[:headings] is set to false
|
||||||
def parse_headings(text, project, obj, attr, only_path, options)
|
def parse_headings(text, project, obj, attr, only_path, options)
|
||||||
headings = []
|
return if options[:headings] == false
|
||||||
|
|
||||||
text.gsub!(HEADING_RE) do
|
text.gsub!(HEADING_RE) do
|
||||||
level, attrs, content = $1.to_i, $2, $3
|
level, attrs, content = $1.to_i, $2, $3
|
||||||
item = strip_tags(content).strip
|
item = strip_tags(content).strip
|
||||||
anchor = item.gsub(%r{[^\w\s\-]}, '').gsub(%r{\s+(\-+\s*)?}, '-')
|
anchor = item.gsub(%r{[^\w\s\-]}, '').gsub(%r{\s+(\-+\s*)?}, '-')
|
||||||
headings << [level, anchor, item]
|
@parsed_headings << [level, anchor, item]
|
||||||
"<h#{level} #{attrs} id=\"#{anchor}\">#{content}<a href=\"##{anchor}\" class=\"wiki-anchor\">¶</a></h#{level}>"
|
"<h#{level} #{attrs} id=\"#{anchor}\">#{content}<a href=\"##{anchor}\" class=\"wiki-anchor\">¶</a></h#{level}>"
|
||||||
end unless options[:headings] == false
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
TOC_RE = /<p>\{\{([<>]?)toc\}\}<\/p>/i unless const_defined?(:TOC_RE)
|
||||||
|
|
||||||
|
# Renders the TOC with given headings
|
||||||
|
def replace_toc(text, headings)
|
||||||
text.gsub!(TOC_RE) do
|
text.gsub!(TOC_RE) do
|
||||||
if headings.empty?
|
if headings.empty?
|
||||||
''
|
''
|
||||||
|
|
|
@ -428,7 +428,11 @@ Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor.
|
||||||
h2. Subtitle with [[Wiki|another Wiki]] link
|
h2. Subtitle with [[Wiki|another Wiki]] link
|
||||||
|
|
||||||
h2. Subtitle with %{color:red}red text%
|
h2. Subtitle with %{color:red}red text%
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
some code
|
||||||
|
</pre>
|
||||||
|
|
||||||
h3. Subtitle with *some* _modifiers_
|
h3. Subtitle with *some* _modifiers_
|
||||||
|
|
||||||
h1. Another title
|
h1. Another title
|
||||||
|
@ -464,7 +468,7 @@ RAW
|
||||||
'</ul>'
|
'</ul>'
|
||||||
|
|
||||||
@project = Project.find(1)
|
@project = Project.find(1)
|
||||||
assert textilizable(raw).gsub("\n", "").include?(expected)
|
assert textilizable(raw).gsub("\n", "").include?(expected), textilizable(raw)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_table_of_content_should_contain_included_page_headings
|
def test_table_of_content_should_contain_included_page_headings
|
||||||
|
|
Loading…
Reference in New Issue