Sha256: 7315b621d89b5d09ed6f268f595c6982e27ae46953de62719e1837b563baf6b2

Contents?: true

Size: 547 Bytes

Versions: 1

Compression:

Stored size: 547 Bytes

Contents

class Govspeak::HtmlValidator
  attr_reader :string

  def initialize(string)
    @string = string.dup.force_encoding(Encoding::UTF_8)
  end

  def invalid?
    !valid?
  end

  def valid?
    dirty_html = govspeak_to_html
    clean_html = Govspeak::HtmlSanitizer.new(dirty_html).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-2.0.2 lib/govspeak/html_validator.rb