diff options
author | Robert Speicher <rspeicher@gmail.com> | 2015-09-01 18:16:56 -0400 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2015-09-01 18:16:56 -0400 |
commit | 5794d65a0743343bfaa367d10d7b0aaa82e20a25 (patch) | |
tree | d258c4fda15f9c40ff70b8fc713169eccfe62846 /lib | |
parent | ca8d225307280750597150b0b969998f99aad4a5 (diff) | |
download | gitlab-ce-5794d65a0743343bfaa367d10d7b0aaa82e20a25.tar.gz |
Add post_process method to Gitlab::Markdown
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/markdown.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/gitlab/markdown.rb b/lib/gitlab/markdown.rb index 478851fc656..dbb8da3f0ad 100644 --- a/lib/gitlab/markdown.rb +++ b/lib/gitlab/markdown.rb @@ -31,6 +31,24 @@ module Gitlab renderer.render(markdown) end + # Perform post-processing on an HTML String + # + # This method is used to perform state-dependent changes to a String of + # HTML, such as removing references that the current user doesn't have + # permission to make (`RedactorFilter`). + # + # html - String to process + # for_user - User state + # + # Returns an HTML-safe String + def self.post_process(html, for_user) + result = post_processor.call(html, current_user: for_user) + + result[:output]. + to_html. + html_safe + end + # Provide autoload paths for filters to prevent a circular dependency error autoload :AutolinkFilter, 'gitlab/markdown/autolink_filter' autoload :CommitRangeReferenceFilter, 'gitlab/markdown/commit_range_reference_filter' @@ -115,6 +133,10 @@ module Gitlab end end + def self.post_processor + @post_processor ||= HTML::Pipeline.new([Gitlab::Markdown::RedactorFilter]) + end + def self.redcarpet_options # https://github.com/vmg/redcarpet#and-its-like-really-simple-to-use @redcarpet_options ||= { |