Sha256: 6cd443f9dc38b22ed872563a0abe30f19ee7c7f17046ee157aec0a78f8c10e8a

Contents?: true

Size: 1.19 KB

Versions: 2

Compression:

Stored size: 1.19 KB

Contents

require 'inky'

def reformat_html(html)
  html
    .gsub(/\s+/, ' ')                                 # Compact all whitespace to a single space
    .gsub(/> *</, ">\n<")                             # Use returns between tags
    .gsub(%r{<(\w+)([^>]*)>\n</\1>}, '<\1\2/>')       # Auto close empty tags, e.g. <hr>\n</hr> => <hr/>
    .gsub(/ "/, '"').gsub(/\=" /, '="')               # Remove leading/trailing spaces inside attributes
    .gsub(/ </, '<').gsub(/> /, '>')                  # Remove leading/trailing spaces inside tags
    .gsub(' data-parsed=""', '')                      # Don't consider this known inky-node artefact
    .gsub('&#xA0', '&#160')                           # These are the same entity...
    .gsub(/(align="[^"]+") (class="[^"]+")/, '\2 \1') # Tweak order to match inky-node on container
    .gsub(/class\="([^"]+)"/) do                      # Sort class names
      classes = $1.split(' ').sort.join(' ')
      %{class="#{classes}"}
    end
end

def expect_same_html(input, expected)
  expect(reformat_html(input)).to eql(reformat_html(expected))
end

def compare(input, expected)
  inky = Inky::Core.new
  output = inky.release_the_kraken(input)
  expect_same_html(output, expected)
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
inky-rb-1.3.7.2 spec/spec_helper.rb
inky-rb-1.3.7.1 spec/spec_helper.rb