diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-23 12:08:38 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-23 12:08:38 +0000 |
commit | 5ad0cf26551baff8f08af8562a8d45e6ec14d71a (patch) | |
tree | 57f1a6bad31bcd11efacd3fdfb9cc92f88fb6a86 /app/helpers/markup_helper.rb | |
parent | f47c768fad17d4c876e96524f83f8306f071db66 (diff) | |
download | gitlab-ce-5ad0cf26551baff8f08af8562a8d45e6ec14d71a.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/helpers/markup_helper.rb')
-rw-r--r-- | app/helpers/markup_helper.rb | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/app/helpers/markup_helper.rb b/app/helpers/markup_helper.rb index d6e466d4678..e24d6a0e8db 100644 --- a/app/helpers/markup_helper.rb +++ b/app/helpers/markup_helper.rb @@ -76,13 +76,14 @@ module MarkupHelper # +max_chars+ limit. If the length limit falls within a tag's contents, then # the tag contents are truncated without removing the closing tag. def first_line_in_markdown(object, attribute, max_chars = nil, options = {}) - md = markdown_field(object, attribute, options) + md = markdown_field(object, attribute, options.merge(post_process: false)) return unless md.present? tags = %w(a gl-emoji b pre code p span) tags << 'img' if options[:allow_images] text = truncate_visible(md, max_chars || md.length) + text = prepare_for_rendering(text, markdown_field_render_context(object, attribute, options)) text = sanitize( text, tags: tags, @@ -107,15 +108,12 @@ module MarkupHelper def markdown_field(object, field, context = {}) object = object.for_display if object.respond_to?(:for_display) - redacted_field_html = object.try(:"redacted_#{field}_html") - return '' unless object.present? - return redacted_field_html if redacted_field_html - html = Banzai.render_field(object, field, context) - context.reverse_merge!(object.banzai_render_context(field)) if object.respond_to?(:banzai_render_context) + redacted_field_html = object.try(:"redacted_#{field}_html") + return redacted_field_html if redacted_field_html - prepare_for_rendering(html, context) + render_markdown_field(object, field, context) end def markup(file_name, text, context = {}) @@ -277,6 +275,23 @@ module MarkupHelper Gitlab::OtherMarkup.render(file_name, text, context) end + def render_markdown_field(object, field, context = {}) + post_process = context.delete(:post_process) + post_process = true if post_process.nil? + + html = Banzai.render_field(object, field, context) + + return html unless post_process + + prepare_for_rendering(html, markdown_field_render_context(object, field, context)) + end + + def markdown_field_render_context(object, field, base_context = {}) + return base_context unless object.respond_to?(:banzai_render_context) + + base_context.reverse_merge(object.banzai_render_context(field)) + end + def prepare_for_rendering(html, context = {}) return '' unless html.present? |