Merged r8871 from trunk.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/1.3-stable@9109 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
09ea1fd58d
commit
4930b3e8bf
@ -490,6 +490,7 @@ module ApplicationHelper
|
|||||||
text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text, :object => obj, :attribute => attr)
|
text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text, :object => obj, :attribute => attr)
|
||||||
|
|
||||||
@parsed_headings = []
|
@parsed_headings = []
|
||||||
|
@heading_anchors = {}
|
||||||
@current_section = 0 if options[:edit_section_links]
|
@current_section = 0 if options[:edit_section_links]
|
||||||
text = parse_non_pre_blocks(text) do |text|
|
text = parse_non_pre_blocks(text) do |text|
|
||||||
[:parse_sections, :parse_inline_attachments, :parse_wiki_links, :parse_redmine_links, :parse_macros, :parse_headings].each do |method_name|
|
[:parse_sections, :parse_inline_attachments, :parse_wiki_links, :parse_redmine_links, :parse_macros, :parse_headings].each do |method_name|
|
||||||
@ -778,6 +779,11 @@ module ApplicationHelper
|
|||||||
anchor = sanitize_anchor_name(item)
|
anchor = sanitize_anchor_name(item)
|
||||||
# used for single-file wiki export
|
# used for single-file wiki export
|
||||||
anchor = "#{obj.page.title}_#{anchor}" if options[:wiki_links] == :anchor && (obj.is_a?(WikiContent) || obj.is_a?(WikiContent::Version))
|
anchor = "#{obj.page.title}_#{anchor}" if options[:wiki_links] == :anchor && (obj.is_a?(WikiContent) || obj.is_a?(WikiContent::Version))
|
||||||
|
@heading_anchors[anchor] ||= 0
|
||||||
|
idx = (@heading_anchors[anchor] += 1)
|
||||||
|
if idx > 1
|
||||||
|
anchor = "#{anchor}-#{idx}"
|
||||||
|
end
|
||||||
@parsed_headings << [level, anchor, item]
|
@parsed_headings << [level, anchor, item]
|
||||||
"<a name=\"#{anchor}\"></a>\n<h#{level} #{attrs}>#{content}<a href=\"##{anchor}\" class=\"wiki-anchor\">¶</a></h#{level}>"
|
"<a name=\"#{anchor}\"></a>\n<h#{level} #{attrs}>#{content}<a href=\"##{anchor}\" class=\"wiki-anchor\">¶</a></h#{level}>"
|
||||||
end
|
end
|
||||||
|
@ -768,6 +768,33 @@ RAW
|
|||||||
assert textilizable(raw).gsub("\n", "").include?(expected)
|
assert textilizable(raw).gsub("\n", "").include?(expected)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_table_of_content_should_generate_unique_anchors
|
||||||
|
raw = <<-RAW
|
||||||
|
{{toc}}
|
||||||
|
|
||||||
|
h1. Title
|
||||||
|
|
||||||
|
h2. Subtitle
|
||||||
|
|
||||||
|
h2. Subtitle
|
||||||
|
RAW
|
||||||
|
|
||||||
|
expected = '<ul class="toc">' +
|
||||||
|
'<li><a href="#Title">Title</a>' +
|
||||||
|
'<ul>' +
|
||||||
|
'<li><a href="#Subtitle">Subtitle</a></li>' +
|
||||||
|
'<li><a href="#Subtitle-2">Subtitle</a></li>'
|
||||||
|
'</ul>'
|
||||||
|
'</li>' +
|
||||||
|
'</ul>'
|
||||||
|
|
||||||
|
@project = Project.find(1)
|
||||||
|
result = textilizable(raw).gsub("\n", "")
|
||||||
|
assert_include expected, result
|
||||||
|
assert_include '<a name="Subtitle">', result
|
||||||
|
assert_include '<a name="Subtitle-2">', result
|
||||||
|
end
|
||||||
|
|
||||||
def test_table_of_content_should_contain_included_page_headings
|
def test_table_of_content_should_contain_included_page_headings
|
||||||
raw = <<-RAW
|
raw = <<-RAW
|
||||||
{{toc}}
|
{{toc}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user