##// END OF EJS Templates
Make sure that anchor names generated for headings fully match wiki links (#7215)....
Etienne Massip -
r7443:65b533a8ec1f
parent child
Show More
@@ -570,6 +570,7 module ApplicationHelper
570 if page =~ /^(.+?)\#(.+)$/
570 if page =~ /^(.+?)\#(.+)$/
571 page, anchor = $1, $2
571 page, anchor = $1, $2
572 end
572 end
573 anchor = sanitize_anchor_name(anchor) if anchor.present?
573 # check if page exists
574 # check if page exists
574 wiki_page = link_project.wiki.find_page(page)
575 wiki_page = link_project.wiki.find_page(page)
575 url = if anchor.present? && wiki_page.present? && (obj.is_a?(WikiContent) || obj.is_a?(WikiContent::Version)) && obj.page == wiki_page
576 url = if anchor.present? && wiki_page.present? && (obj.is_a?(WikiContent) || obj.is_a?(WikiContent::Version)) && obj.page == wiki_page
@@ -727,7 +728,7 module ApplicationHelper
727 text.gsub!(HEADING_RE) do
728 text.gsub!(HEADING_RE) do
728 level, attrs, content = $1.to_i, $2, $3
729 level, attrs, content = $1.to_i, $2, $3
729 item = strip_tags(content).strip
730 item = strip_tags(content).strip
730 anchor = item.gsub(%r{[^\w\s\-]}, '').gsub(%r{\s+(\-+\s*)?}, '-')
731 anchor = sanitize_anchor_name(item)
731 # used for single-file wiki export
732 # used for single-file wiki export
732 anchor = "#{obj.page.title}_#{anchor}" if options[:wiki_links] == :anchor && (obj.is_a?(WikiContent) || obj.is_a?(WikiContent::Version))
733 anchor = "#{obj.page.title}_#{anchor}" if options[:wiki_links] == :anchor && (obj.is_a?(WikiContent) || obj.is_a?(WikiContent::Version))
733 @parsed_headings << [level, anchor, item]
734 @parsed_headings << [level, anchor, item]
@@ -919,6 +920,10 module ApplicationHelper
919 end
920 end
920 end
921 end
921
922
923 def sanitize_anchor_name(anchor)
924 anchor.gsub(%r{[^\w\s\-]}, '').gsub(%r{\s+(\-+\s*)?}, '-')
925 end
926
922 # Returns the javascript tags that are included in the html layout head
927 # Returns the javascript tags that are included in the html layout head
923 def javascript_heads
928 def javascript_heads
924 tags = javascript_include_tag(:defaults)
929 tags = javascript_include_tag(:defaults)
@@ -553,6 +553,16 EXPECTED
553 assert_equal expected, textilizable(raw)
553 assert_equal expected, textilizable(raw)
554 end
554 end
555
555
556 def test_headings_with_special_chars
557 # This test makes sure that the generated anchor names match the expected
558 # ones even if the heading text contains unconventional characters
559 raw = 'h1. Some heading related to version 0.5'
560 anchor = sanitize_anchor_name("Some-heading-related-to-version-0.5")
561 expected = %|<a name="#{anchor}"></a>\n<h1 >Some heading related to version 0.5<a href="##{anchor}" class="wiki-anchor">&para;</a></h1>|
562
563 assert_equal expected, textilizable(raw)
564 end
565
556 def test_wiki_links_within_wiki_page_context
566 def test_wiki_links_within_wiki_page_context
557
567
558 page = WikiPage.find_by_title('Another_page' )
568 page = WikiPage.find_by_title('Another_page' )
General Comments 0
You need to be logged in to leave comments. Login now