@@ -490,6 +490,7 module ApplicationHelper | |||||
490 | text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text, :object => obj, :attribute => attr) |
|
490 | text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text, :object => obj, :attribute => attr) | |
491 |
|
491 | |||
492 | @parsed_headings = [] |
|
492 | @parsed_headings = [] | |
|
493 | @heading_anchors = {} | |||
493 | @current_section = 0 if options[:edit_section_links] |
|
494 | @current_section = 0 if options[:edit_section_links] | |
494 | text = parse_non_pre_blocks(text) do |text| |
|
495 | text = parse_non_pre_blocks(text) do |text| | |
495 | [:parse_sections, :parse_inline_attachments, :parse_wiki_links, :parse_redmine_links, :parse_macros, :parse_headings].each do |method_name| |
|
496 | [: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 | |||||
778 | anchor = sanitize_anchor_name(item) |
|
779 | anchor = sanitize_anchor_name(item) | |
779 | # used for single-file wiki export |
|
780 | # used for single-file wiki export | |
780 | anchor = "#{obj.page.title}_#{anchor}" if options[:wiki_links] == :anchor && (obj.is_a?(WikiContent) || obj.is_a?(WikiContent::Version)) |
|
781 | anchor = "#{obj.page.title}_#{anchor}" if options[:wiki_links] == :anchor && (obj.is_a?(WikiContent) || obj.is_a?(WikiContent::Version)) | |
|
782 | @heading_anchors[anchor] ||= 0 | |||
|
783 | idx = (@heading_anchors[anchor] += 1) | |||
|
784 | if idx > 1 | |||
|
785 | anchor = "#{anchor}-#{idx}" | |||
|
786 | end | |||
781 | @parsed_headings << [level, anchor, item] |
|
787 | @parsed_headings << [level, anchor, item] | |
782 | "<a name=\"#{anchor}\"></a>\n<h#{level} #{attrs}>#{content}<a href=\"##{anchor}\" class=\"wiki-anchor\">¶</a></h#{level}>" |
|
788 | "<a name=\"#{anchor}\"></a>\n<h#{level} #{attrs}>#{content}<a href=\"##{anchor}\" class=\"wiki-anchor\">¶</a></h#{level}>" | |
783 | end |
|
789 | end |
@@ -768,6 +768,33 RAW | |||||
768 | assert textilizable(raw).gsub("\n", "").include?(expected) |
|
768 | assert textilizable(raw).gsub("\n", "").include?(expected) | |
769 | end |
|
769 | end | |
770 |
|
770 | |||
|
771 | def test_table_of_content_should_generate_unique_anchors | |||
|
772 | raw = <<-RAW | |||
|
773 | {{toc}} | |||
|
774 | ||||
|
775 | h1. Title | |||
|
776 | ||||
|
777 | h2. Subtitle | |||
|
778 | ||||
|
779 | h2. Subtitle | |||
|
780 | RAW | |||
|
781 | ||||
|
782 | expected = '<ul class="toc">' + | |||
|
783 | '<li><a href="#Title">Title</a>' + | |||
|
784 | '<ul>' + | |||
|
785 | '<li><a href="#Subtitle">Subtitle</a></li>' + | |||
|
786 | '<li><a href="#Subtitle-2">Subtitle</a></li>' | |||
|
787 | '</ul>' | |||
|
788 | '</li>' + | |||
|
789 | '</ul>' | |||
|
790 | ||||
|
791 | @project = Project.find(1) | |||
|
792 | result = textilizable(raw).gsub("\n", "") | |||
|
793 | assert_include expected, result | |||
|
794 | assert_include '<a name="Subtitle">', result | |||
|
795 | assert_include '<a name="Subtitle-2">', result | |||
|
796 | end | |||
|
797 | ||||
771 | def test_table_of_content_should_contain_included_page_headings |
|
798 | def test_table_of_content_should_contain_included_page_headings | |
772 | raw = <<-RAW |
|
799 | raw = <<-RAW | |
773 | {{toc}} |
|
800 | {{toc}} |
General Comments 0
You need to be logged in to leave comments.
Login now