diff --git a/app/helpers/markup_helper.rb b/app/helpers/markup_helper.rb index a73f962e4ff..6b826dac84c 100644 --- a/app/helpers/markup_helper.rb +++ b/app/helpers/markup_helper.rb @@ -115,13 +115,13 @@ module MarkupHelper text = wiki_page.content return '' unless text.present? - context.merge!({ + context.merge!( pipeline: :wiki, project: @project, project_wiki: @project_wiki, page_slug: wiki_page.slug, issuable_state_filter_enabled: true - }) + ) html = case wiki_page.format diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 18b3badda8d..1c3dbed8d4a 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -252,6 +252,10 @@ module ProjectsHelper "xcode://clone?repo=#{CGI.escape(default_url_to_repo(project))}" end + def legacy_render_context(params) + params[:legacy_render] ? { markdown_engine: :redcarpet } : {} + end + private def get_project_nav_tabs(project, current_user) diff --git a/app/views/projects/_wiki.html.haml b/app/views/projects/_wiki.html.haml index 0737f94e766..5adca007f7e 100644 --- a/app/views/projects/_wiki.html.haml +++ b/app/views/projects/_wiki.html.haml @@ -2,8 +2,7 @@ %div{ class: container_class } .prepend-top-default.append-bottom-default .wiki - - context = params[:legacy_render] ? { markdown_engine: :redcarpet} : {} - = render_wiki_content(@wiki_home, context) + = render_wiki_content(@wiki_home, legacy_render_context(params)) - else - can_create_wiki = can?(current_user, :create_wiki, @project) .project-home-empty{ class: [('row-content-block' if can_create_wiki), ('content-block' unless can_create_wiki)] } diff --git a/app/views/projects/blob/preview.html.haml b/app/views/projects/blob/preview.html.haml index da29eb7a133..eb65cd90ea8 100644 --- a/app/views/projects/blob/preview.html.haml +++ b/app/views/projects/blob/preview.html.haml @@ -2,8 +2,7 @@ .diff-content - if markup?(@blob.name) .file-content.wiki - - context = params[:legacy_render] ? { markdown_engine: :redcarpet} : {} - = markup(@blob.name, @content, context) + = markup(@blob.name, @content, legacy_render_context(params)) - else .file-content.code.js-syntax-highlight - unless @diff_lines.empty? diff --git a/app/views/projects/blob/viewers/_markup.html.haml b/app/views/projects/blob/viewers/_markup.html.haml index ced08c659a9..bd12cadf240 100644 --- a/app/views/projects/blob/viewers/_markup.html.haml +++ b/app/views/projects/blob/viewers/_markup.html.haml @@ -1,8 +1,6 @@ - blob = viewer.blob -- context = {} -- if params[:legacy_render] - - context[:markdown_engine] = :redcarpet -- else +- context = legacy_render_context(params) +- unless context[:markdown_engine] == :redcarpet - context[:rendered] = blob.rendered_markup if blob.respond_to?(:rendered_markup) .file-content.wiki = markup(blob.name, blob.data, context) diff --git a/app/views/projects/wikis/_sidebar.html.haml b/app/views/projects/wikis/_sidebar.html.haml index 6542ef3b4e0..02c5a6ea55c 100644 --- a/app/views/projects/wikis/_sidebar.html.haml +++ b/app/views/projects/wikis/_sidebar.html.haml @@ -12,8 +12,7 @@ .blocks-container .block.block-first - if @sidebar_page - - context = params[:legacy_render] ? { markdown_engine: :redcarpet} : {} - = render_wiki_content(@sidebar_page, context) + = render_wiki_content(@sidebar_page, legacy_render_context(params)) - else %ul.wiki-pages = render @sidebar_wiki_entries, context: 'sidebar' diff --git a/app/views/projects/wikis/show.html.haml b/app/views/projects/wikis/show.html.haml index eb1410fc87d..19b9744b508 100644 --- a/app/views/projects/wikis/show.html.haml +++ b/app/views/projects/wikis/show.html.haml @@ -26,7 +26,6 @@ .prepend-top-default.append-bottom-default .wiki - - context = params[:legacy_render] ? { markdown_engine: :redcarpet} : {} - = render_wiki_content(@page, context) + = render_wiki_content(@page, legacy_render_context(params)) = render 'sidebar' diff --git a/app/views/search/results/_snippet_blob.html.haml b/app/views/search/results/_snippet_blob.html.haml index 6527d70134e..8b95bdf9747 100644 --- a/app/views/search/results/_snippet_blob.html.haml +++ b/app/views/search/results/_snippet_blob.html.haml @@ -21,8 +21,7 @@ .file-content.wiki - snippet_chunks.each do |chunk| - unless chunk[:data].empty? - - context = params[:legacy_render] ? { markdown_engine: :redcarpet} : {} - = markup(snippet.file_name, chunk[:data], context) + = markup(snippet.file_name, chunk[:data], legacy_render_context(params)) - else .file-content.code .nothing-here-block Empty file diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb index cbd4ff0fb4a..976b6c312b4 100644 --- a/spec/helpers/projects_helper_spec.rb +++ b/spec/helpers/projects_helper_spec.rb @@ -470,4 +470,16 @@ describe ProjectsHelper do end end end + + describe '#legacy_render_context' do + it 'returns the redcarpet engine' do + params = { legacy_render: '1' } + + expect(helper.legacy_render_context(params)).to include(markdown_engine: :redcarpet) + end + + it 'returns nothing' do + expect(helper.legacy_render_context({})).to be_empty + end + end end