diff options
Diffstat (limited to 'app/helpers/markup_helper.rb')
-rw-r--r-- | app/helpers/markup_helper.rb | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/app/helpers/markup_helper.rb b/app/helpers/markup_helper.rb index 66f4b7b3f30..7eb193bd087 100644 --- a/app/helpers/markup_helper.rb +++ b/app/helpers/markup_helper.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'nokogiri' +require "nokogiri" module MarkupHelper include ActionView::Helpers::TagHelper @@ -24,7 +24,7 @@ module MarkupHelper # Use this in places where you would normally use link_to(gfm(...), ...). def link_to_markdown(body, url, html_options = {}) - return '' if body.blank? + return "" if body.blank? link_to_html(markdown(body, pipeline: :single_line), url, html_options) end @@ -45,7 +45,7 @@ module MarkupHelper def link_to_html(redacted, url, html_options = {}) fragment = Nokogiri::HTML::DocumentFragment.parse(redacted) - if fragment.children.size == 1 && fragment.children[0].name == 'a' + if fragment.children.size == 1 && fragment.children[0].name == "a" # Fragment has only one node, and it's a link generated by `gfm`. # Replace it with our requested link. text = fragment.children[0].text @@ -62,7 +62,7 @@ module MarkupHelper # Add any custom CSS classes to the GFM-generated reference links if html_options[:class] - fragment.css('a.gfm').add_class(html_options[:class]) + fragment.css("a.gfm").add_class(html_options[:class]) end fragment.to_html.html_safe @@ -76,14 +76,14 @@ module MarkupHelper md = markdown_field(object, attribute, options) return nil unless md.present? - tags = %w(a gl-emoji b pre code p span) - tags << 'img' if options[:allow_images] + 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 = sanitize( text, tags: tags, - attributes: Rails::Html::WhiteListSanitizer.allowed_attributes + ['style', 'data-src', 'data-name', 'data-unicode-version'] + attributes: Rails::Html::WhiteListSanitizer.allowed_attributes + ["style", "data-src", "data-name", "data-unicode-version"] ) # since <img> tags are stripped, this can leave empty <a> tags hanging around @@ -92,7 +92,7 @@ module MarkupHelper end def markdown(text, context = {}) - return '' unless text.present? + return "" unless text.present? context[:project] ||= @project context[:group] ||= @group @@ -105,7 +105,7 @@ module MarkupHelper object = object.for_display if object.respond_to?(:for_display) redacted_field_html = object.try(:"redacted_#{field}_html") - return '' unless object.present? + return "" unless object.present? return redacted_field_html if redacted_field_html html = Banzai.render_field(object, field, context) @@ -122,7 +122,7 @@ module MarkupHelper def render_wiki_content(wiki_page, context = {}) text = wiki_page.content - return '' unless text.present? + return "" unless text.present? context.merge!( pipeline: :wiki, @@ -146,14 +146,14 @@ module MarkupHelper end def markup_unsafe(file_name, text, context = {}) - return '' unless text.present? + return "" unless text.present? if gitlab_markdown?(file_name) markdown_unsafe(text, context) elsif asciidoc?(file_name) asciidoc_unsafe(text, context) elsif plain?(file_name) - content_tag :pre, class: 'plain-readme' do + content_tag :pre, class: "plain-readme" do text end else @@ -181,7 +181,7 @@ module MarkupHelper if entity.respond_to?(:to_reference) entity.to_reference(project, full: true) else - '' + "" end end @@ -228,7 +228,7 @@ module MarkupHelper def truncate_if_block(node, truncated) return true if truncated - if node.element? && (node.description&.block? || node.matches?('pre > code > .line')) + if node.element? && (node.description&.block? || node.matches?("pre > code > .line")) node.inner_html = "#{node.inner_html}..." if node.next_sibling true else @@ -237,9 +237,9 @@ module MarkupHelper end def strip_empty_link_tags(text) - scrubber = Loofah::Scrubber.new do |node| - node.remove if node.name == 'a' && node.content.blank? - end + scrubber = Loofah::Scrubber.new { |node| + node.remove if node.name == "a" && node.content.blank? + } # Use `Loofah` directly instead of `sanitize` # as we still use the `rails-deprecated_sanitizer` gem @@ -247,14 +247,14 @@ module MarkupHelper end def markdown_toolbar_button(options = {}) - data = options[:data].merge({ container: 'body' }) + data = options[:data].merge({container: "body"}) content_tag :button, - type: 'button', - class: 'toolbar-btn js-md has-tooltip', + type: "button", + class: "toolbar-btn js-md has-tooltip", tabindex: -1, data: data, title: options[:title], - aria: { label: options[:title] } do + aria: {label: options[:title]} do sprite_icon(options[:icon]) end end @@ -272,15 +272,15 @@ module MarkupHelper end def prepare_for_rendering(html, context = {}) - return '' unless html.present? + return "" unless html.present? context.merge!( current_user: (current_user if defined?(current_user)), # RelativeLinkFilter - commit: @commit, - project_wiki: @project_wiki, - ref: @ref, + commit: @commit, + project_wiki: @project_wiki, + ref: @ref, requested_path: @path ) |