Sha256: f1ec0fb1e4d5df1e9fa353ea7a9f91d297933115dd90203af69288fba5f6938d
Contents?: true
Size: 1.33 KB
Versions: 1
Compression:
Stored size: 1.33 KB
Contents
require 'codeqa/utils/erb_sanitizer' module Codeqa module Checkers class HtmlValidator < Checker def self.check?(sourcefile) sourcefile.html? end def self.available? nokogiri? end def name 'html' end def hint 'Nokogiri found XHTML errors, please fix them.' end REMOVED_NOKOGIRI_ERRORS = Regexp.union( /Opening and ending tag mismatch: (special line 1|\w+ line 1 and special)/, /Premature end of data in tag special/, /Extra content at the end of the document/, /xmlParseEntityRef: no name/ ) def check return unless self.class.nokogiri? doc = Nokogiri::XML "<special>#{stripped_html}</special>" doc.errors.delete_if{ |e| e.message =~ REMOVED_NOKOGIRI_ERRORS } errors.add(:source, sourcefile.content) unless doc.errors.empty? # errors.add(:source, stripped_html) unless doc.errors.empty? doc.errors.each do |error| errors.add(error.line, error.message) unless error.warning? end end def stripped_html @html ||= ErbSanitizer.new(sourcefile.content).result end def self.nokogiri? @loaded ||= begin require 'nokogiri' true end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
codeqa-0.4.0.pre | lib/codeqa/checkers/html_validator.rb |