Sha256: 217f944520f622d2d1886de4e2d40eee14b07e22f4428152c34c6e4d764fc4fe

Contents?: true

Size: 646 Bytes

Versions: 1

Compression:

Stored size: 646 Bytes

Contents

class Govspeak::HtmlValidator
  attr_reader :string

  def initialize(string, sanitization_options = {})
    @string = string.dup.force_encoding(Encoding::UTF_8)
    @sanitization_options = sanitization_options
  end

  def invalid?
    !valid?
  end

  def valid?
    dirty_html = govspeak_to_html
    clean_html = Govspeak::HtmlSanitizer.new(dirty_html, @sanitization_options).sanitize
    normalise_html(dirty_html) == normalise_html(clean_html)
  end

  # Make whitespace in html tags consistent
  def normalise_html(html)
    Nokogiri::HTML.parse(html).to_s
  end

  def govspeak_to_html
    Govspeak::Document.new(string).to_html
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
govspeak-3.0.0 lib/govspeak/html_validator.rb