Sha256: bde84162bc91e33cb6cb884115229d2b398aa8fdeabac37c223281d0d1f3defd

Contents?: true

Size: 708 Bytes

Versions: 5

Compression:

Stored size: 708 Bytes

Contents

class Govspeak::HtmlValidator
  attr_reader :govspeak_string

  def initialize(govspeak_string, sanitization_options = {})
    @govspeak_string = govspeak_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(govspeak_string, sanitize: false).to_html
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
govspeak-6.2.1 lib/govspeak/html_validator.rb
govspeak-6.2.0 lib/govspeak/html_validator.rb
govspeak-6.1.1 lib/govspeak/html_validator.rb
govspeak-6.1.0 lib/govspeak/html_validator.rb
govspeak-6.0.0 lib/govspeak/html_validator.rb