diff options
Diffstat (limited to 'app/helpers/gitlab_markdown_helper.rb')
-rw-r--r-- | app/helpers/gitlab_markdown_helper.rb | 55 |
1 files changed, 29 insertions, 26 deletions
diff --git a/app/helpers/gitlab_markdown_helper.rb b/app/helpers/gitlab_markdown_helper.rb index eb3f72a307d..1ebfd92f119 100644 --- a/app/helpers/gitlab_markdown_helper.rb +++ b/app/helpers/gitlab_markdown_helper.rb @@ -1,9 +1,6 @@ require 'nokogiri' module GitlabMarkdownHelper - include Gitlab::Markdown - include PreferencesHelper - # Use this in places where you would normally use link_to(gfm(...), ...). # # It solves a problem occurring with nested links (i.e. @@ -22,7 +19,7 @@ module GitlabMarkdownHelper escape_once(body) end - gfm_body = gfm(escaped_body, {}, html_options) + gfm_body = Gitlab::Markdown.gfm(escaped_body, project: @project, current_user: current_user) fragment = Nokogiri::XML::DocumentFragment.parse(gfm_body) if fragment.children.size == 1 && fragment.children[0].name == 'a' @@ -39,32 +36,38 @@ module GitlabMarkdownHelper end end + # Add any custom CSS classes to the GFM-generated reference links + if html_options[:class] + fragment.css('a.gfm').add_class(html_options[:class]) + end + fragment.to_html.html_safe end - MARKDOWN_OPTIONS = { - no_intra_emphasis: true, - tables: true, - fenced_code_blocks: true, - strikethrough: true, - lax_spacing: true, - space_after_headers: true, - superscript: true, - footnotes: true - }.freeze - - def markdown(text, options={}) - unless @markdown && options == @options - @options = options - - # see https://github.com/vmg/redcarpet#darling-i-packed-you-a-couple-renderers-for-lunch - rend = Redcarpet::Render::GitlabHTML.new(self, user_color_scheme_class, options) - - # see https://github.com/vmg/redcarpet#and-its-like-really-simple-to-use - @markdown = Redcarpet::Markdown.new(rend, MARKDOWN_OPTIONS) - end + def markdown(text, context = {}) + context.merge!( + current_user: current_user, + path: @path, + project: @project, + project_wiki: @project_wiki, + ref: @ref + ) + + Gitlab::Markdown.render(text, context) + end + + # TODO (rspeicher): Remove all usages of this helper and just call `markdown` + # with a custom pipeline depending on the content being rendered + def gfm(text, options = {}) + options.merge!( + current_user: current_user, + path: @path, + project: @project, + project_wiki: @project_wiki, + ref: @ref + ) - @markdown.render(text).html_safe + Gitlab::Markdown.gfm(text, options) end def asciidoc(text) |