class HTMLPipeline::NodeFilter::ImageMaxWidthFilter

This filter rewrites image tags with a max-width inline style and also wraps the image in an <a> tag that causes the full size image to be opened in a new tab.

The max-width inline styles are especially useful in HTML email which don’t use a global stylesheets.

Constants

SELECTOR

Public Instance Methods

handle_element(element) click to toggle source
# File lib/html_pipeline/node_filter/image_max_width_filter.rb, line 18
def handle_element(element)
  # Skip if there's already a style attribute. Not sure how this
  # would happen but we can reconsider it in the future.
  return if element["style"]

  # Bail out if src doesn't look like a valid http url. trying to avoid weird
  # js injection via javascript: urls.
  return if /\Ajavascript/i.match?(element["src"].to_s.strip)

  element["style"] = "max-width:100%;"

  link_image(element) unless has_ancestor?(element, "a")
end
selector() click to toggle source
# File lib/html_pipeline/node_filter/image_max_width_filter.rb, line 14
def selector
  SELECTOR
end