diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 01b96b5eb..12cee39f0 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -556,7 +556,7 @@ module ApplicationHelper "##{anchor}" else case options[:wiki_links] - when :local; "#{title}.html" + when :local; "#{page.present? ? Wiki.titleize(page) : ''}.html" + (anchor.present? ? "##{anchor}" : '') when :anchor; "##{title}" # used for single-file wiki export else wiki_page_id = page.present? ? Wiki.titleize(page) : nil diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb index 0608894e3..f73d67992 100644 --- a/test/unit/helpers/application_helper_test.rb +++ b/test/unit/helpers/application_helper_test.rb @@ -375,6 +375,26 @@ RAW to_test.each { |text, result| assert_equal "

#{result}

", textilizable(text) } end + def test_wiki_links_within_local_file_generation_context + + to_test = { + # link to a page + '[[CookBook documentation]]' => 'CookBook documentation', + '[[CookBook documentation|documentation]]' => 'documentation', + '[[CookBook documentation#One-section]]' => 'CookBook documentation', + '[[CookBook documentation#One-section|documentation]]' => 'documentation', + # page that doesn't exist + '[[Unknown page]]' => 'Unknown page', + '[[Unknown page|404]]' => '404', + '[[Unknown page#anchor]]' => 'Unknown page', + '[[Unknown page#anchor|404]]' => '404', + } + + @project = Project.find(1) + + to_test.each { |text, result| assert_equal "

#{result}

", textilizable(text, :wiki_links => :local) } + end + def test_html_tags to_test = { "
content
" => "

<div>content</div>

",