@@ -503,6 +503,7 module ApplicationHelper | |||||
503 | text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text, :object => obj, :attribute => attr) |
|
503 | text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text, :object => obj, :attribute => attr) | |
504 |
|
504 | |||
505 | @parsed_headings = [] |
|
505 | @parsed_headings = [] | |
|
506 | @heading_anchors = {} | |||
506 | @current_section = 0 if options[:edit_section_links] |
|
507 | @current_section = 0 if options[:edit_section_links] | |
507 |
|
508 | |||
508 | parse_sections(text, project, obj, attr, only_path, options) |
|
509 | parse_sections(text, project, obj, attr, only_path, options) | |
@@ -816,6 +817,11 module ApplicationHelper | |||||
816 | anchor = sanitize_anchor_name(item) |
|
817 | anchor = sanitize_anchor_name(item) | |
817 | # used for single-file wiki export |
|
818 | # used for single-file wiki export | |
818 | anchor = "#{obj.page.title}_#{anchor}" if options[:wiki_links] == :anchor && (obj.is_a?(WikiContent) || obj.is_a?(WikiContent::Version)) |
|
819 | anchor = "#{obj.page.title}_#{anchor}" if options[:wiki_links] == :anchor && (obj.is_a?(WikiContent) || obj.is_a?(WikiContent::Version)) | |
|
820 | @heading_anchors[anchor] ||= 0 | |||
|
821 | idx = (@heading_anchors[anchor] += 1) | |||
|
822 | if idx > 1 | |||
|
823 | anchor = "#{anchor}-#{idx}" | |||
|
824 | end | |||
819 | @parsed_headings << [level, anchor, item] |
|
825 | @parsed_headings << [level, anchor, item] | |
820 | "<a name=\"#{anchor}\"></a>\n<h#{level} #{attrs}>#{content}<a href=\"##{anchor}\" class=\"wiki-anchor\">¶</a></h#{level}>" |
|
826 | "<a name=\"#{anchor}\"></a>\n<h#{level} #{attrs}>#{content}<a href=\"##{anchor}\" class=\"wiki-anchor\">¶</a></h#{level}>" | |
821 | end |
|
827 | end |
@@ -837,6 +837,33 RAW | |||||
837 | assert textilizable(raw).gsub("\n", "").include?(expected) |
|
837 | assert textilizable(raw).gsub("\n", "").include?(expected) | |
838 | end |
|
838 | end | |
839 |
|
839 | |||
|
840 | def test_table_of_content_should_generate_unique_anchors | |||
|
841 | raw = <<-RAW | |||
|
842 | {{toc}} | |||
|
843 | ||||
|
844 | h1. Title | |||
|
845 | ||||
|
846 | h2. Subtitle | |||
|
847 | ||||
|
848 | h2. Subtitle | |||
|
849 | RAW | |||
|
850 | ||||
|
851 | expected = '<ul class="toc">' + | |||
|
852 | '<li><a href="#Title">Title</a>' + | |||
|
853 | '<ul>' + | |||
|
854 | '<li><a href="#Subtitle">Subtitle</a></li>' + | |||
|
855 | '<li><a href="#Subtitle-2">Subtitle</a></li>' | |||
|
856 | '</ul>' | |||
|
857 | '</li>' + | |||
|
858 | '</ul>' | |||
|
859 | ||||
|
860 | @project = Project.find(1) | |||
|
861 | result = textilizable(raw).gsub("\n", "") | |||
|
862 | assert_include expected, result | |||
|
863 | assert_include '<a name="Subtitle">', result | |||
|
864 | assert_include '<a name="Subtitle-2">', result | |||
|
865 | end | |||
|
866 | ||||
840 | def test_table_of_content_should_contain_included_page_headings |
|
867 | def test_table_of_content_should_contain_included_page_headings | |
841 | raw = <<-RAW |
|
868 | raw = <<-RAW | |
842 | {{toc}} |
|
869 | {{toc}} |
General Comments 0
You need to be logged in to leave comments.
Login now