Sha256: 755b6b69585bd02834305ccbabb5043326ff73ec64bdfea51de8dac9ac1f56f8

Contents?: true

Size: 691 Bytes

Versions: 29

Compression:

Stored size: 691 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).to_html
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
govspeak-5.9.1 lib/govspeak/html_validator.rb
govspeak-5.9.0 lib/govspeak/html_validator.rb
govspeak-5.8.0 lib/govspeak/html_validator.rb
govspeak-5.7.1 lib/govspeak/html_validator.rb
govspeak-5.7.0 lib/govspeak/html_validator.rb
govspeak-5.6.0 lib/govspeak/html_validator.rb
govspeak-5.5.0 lib/govspeak/html_validator.rb
govspeak-5.4.0 lib/govspeak/html_validator.rb
govspeak-5.3.0 lib/govspeak/html_validator.rb
govspeak-5.2.2 lib/govspeak/html_validator.rb
govspeak-5.2.1 lib/govspeak/html_validator.rb
govspeak-5.2.0 lib/govspeak/html_validator.rb
govspeak-5.1.0 lib/govspeak/html_validator.rb
govspeak-5.0.3 lib/govspeak/html_validator.rb
govspeak-5.0.2 lib/govspeak/html_validator.rb
govspeak-5.0.1 lib/govspeak/html_validator.rb
govspeak-5.0.0 lib/govspeak/html_validator.rb
govspeak-4.0.0 lib/govspeak/html_validator.rb
govspeak-3.6.2 lib/govspeak/html_validator.rb
govspeak-3.6.1 lib/govspeak/html_validator.rb