diff options
Diffstat (limited to 'app/helpers/markup_helper.rb')
-rw-r--r-- | app/helpers/markup_helper.rb | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/app/helpers/markup_helper.rb b/app/helpers/markup_helper.rb index 4a5720e757d..91fce6d6820 100644 --- a/app/helpers/markup_helper.rb +++ b/app/helpers/markup_helper.rb @@ -80,9 +80,7 @@ module MarkupHelper ) ) - # since <img> tags are stripped, this can leave empty <a> tags hanging around - # (as our markdown wraps images in links) - strip_empty_link_tags(text).html_safe + render_links(text) end def markdown(text, context = {}) @@ -171,9 +169,22 @@ module MarkupHelper { project: wiki.container } end - def strip_empty_link_tags(text) + # Sanitize and style user references links + # + # @param String text the string to be sanitized + # + # 1. Remove empty <a> tags which are caused by the <img> tags being stripped + # (as our markdown wraps images in links) + # 2. Strip all link tags, except user references, leaving just the link text + # 3. Add a highlight class for current user's references + # + # @return sanitized HTML string + def render_links(text) scrubber = Loofah::Scrubber.new do |node| - node.remove if node.name == 'a' && node.children.empty? + next unless node.name == 'a' + next node.remove if node.children.empty? + next node.replace(node.children) if node['data-reference-type'] != 'user' + next node.append_class('current-user') if current_user && node['data-user'] == current_user.id.to_s end sanitize text, scrubber: scrubber @@ -181,7 +192,7 @@ module MarkupHelper def markdown_toolbar_button(options = {}) data = options[:data].merge({ container: 'body' }) - css_classes = %w[gl-button btn btn-default-tertiary btn-icon js-md has-tooltip] << options[:css_class].to_s + css_classes = %w[gl-button btn btn-default-tertiary btn-icon btn-sm js-md has-tooltip] << options[:css_class].to_s content_tag :button, type: 'button', class: css_classes.join(' '), |