##// END OF EJS Templates
Merged #7563 from trunk (#7215)....
Etienne Massip -
r7444:605f1745ffc8
parent child
Show More
@@ -550,6 +550,7 module ApplicationHelper
550 if page =~ /^(.+?)\#(.+)$/
550 if page =~ /^(.+?)\#(.+)$/
551 page, anchor = $1, $2
551 page, anchor = $1, $2
552 end
552 end
553 anchor = sanitize_anchor_name(anchor) if anchor.present?
553 # check if page exists
554 # check if page exists
554 wiki_page = link_project.wiki.find_page(page)
555 wiki_page = link_project.wiki.find_page(page)
555 url = if anchor.present? && wiki_page.present? && (obj.is_a?(WikiContent) || obj.is_a?(WikiContent::Version)) && obj.page == wiki_page
556 url = if anchor.present? && wiki_page.present? && (obj.is_a?(WikiContent) || obj.is_a?(WikiContent::Version)) && obj.page == wiki_page
@@ -707,7 +708,7 module ApplicationHelper
707 text.gsub!(HEADING_RE) do
708 text.gsub!(HEADING_RE) do
708 level, attrs, content = $1.to_i, $2, $3
709 level, attrs, content = $1.to_i, $2, $3
709 item = strip_tags(content).strip
710 item = strip_tags(content).strip
710 anchor = item.gsub(%r{[^\w\s\-]}, '').gsub(%r{\s+(\-+\s*)?}, '-')
711 anchor = sanitize_anchor_name(item)
711 @parsed_headings << [level, anchor, item]
712 @parsed_headings << [level, anchor, item]
712 "<a name=\"#{anchor}\"></a>\n<h#{level} #{attrs}>#{content}<a href=\"##{anchor}\" class=\"wiki-anchor\">&para;</a></h#{level}>"
713 "<a name=\"#{anchor}\"></a>\n<h#{level} #{attrs}>#{content}<a href=\"##{anchor}\" class=\"wiki-anchor\">&para;</a></h#{level}>"
713 end
714 end
@@ -893,6 +894,10 module ApplicationHelper
893 end
894 end
894 end
895 end
895
896
897 def sanitize_anchor_name(anchor)
898 anchor.gsub(%r{[^\w\s\-]}, '').gsub(%r{\s+(\-+\s*)?}, '-')
899 end
900
896 # Returns the javascript tags that are included in the html layout head
901 # Returns the javascript tags that are included in the html layout head
897 def javascript_heads
902 def javascript_heads
898 tags = javascript_include_tag(:defaults)
903 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