diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index bec54a83e..9790848e8 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -489,6 +489,7 @@ module ApplicationHelper text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text, :object => obj, :attribute => attr) @parsed_headings = [] + @current_section = 0 if options[:edit_section_links] 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| send method_name, text, project, obj, attr, only_path, options @@ -732,12 +733,11 @@ module ApplicationHelper def parse_sections(text, project, obj, attr, only_path, options) return unless options[:edit_section_links] - section = 0 text.gsub!(HEADING_RE) do - section += 1 - if section > 1 + @current_section += 1 + if @current_section > 1 content_tag('div', - link_to(image_tag('edit.png'), options[:edit_section_links].merge(:section => section)), + link_to(image_tag('edit.png'), options[:edit_section_links].merge(:section => @current_section)), :class => 'contextual', :title => l(:button_edit_section)) + $1 else diff --git a/test/fixtures/wiki_contents.yml b/test/fixtures/wiki_contents.yml index b5fd01080..d65f523ff 100644 --- a/test/fixtures/wiki_contents.yml +++ b/test/fixtures/wiki_contents.yml @@ -111,6 +111,8 @@ wiki_contents_011: h2. Heading 1 + @WHATEVER@ + Maecenas sed elit sit amet mi accumsan vestibulum non nec velit. Proin porta tincidunt lorem, consequat rhoncus dolor fermentum in. Cras ipsum felis, ultrices at porttitor vel, faucibus eu nunc. diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb index 1274e676b..8d2187b47 100644 --- a/test/functional/wiki_controller_test.rb +++ b/test/functional/wiki_controller_test.rb @@ -79,6 +79,20 @@ class WikiControllerTest < ActionController::TestCase get :show, :project_id => 1, :id => 'Unexistent page' assert_response 404 end + + def test_show_should_display_section_edit_links + @request.session[:user_id] = 2 + get :show, :project_id => 1, :id => 'Page with sections' + assert_no_tag 'a', :attributes => { + :href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=1' + } + assert_tag 'a', :attributes => { + :href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=2' + } + assert_tag 'a', :attributes => { + :href => '/projects/ecookbook/wiki/Page_with_sections/edit?section=3' + } + end def test_show_unexistent_page_with_edit_right @request.session[:user_id] = 2