Class: Canon::Validators::HtmlValidator
- Inherits:
-
BaseValidator
- Object
- BaseValidator
- Canon::Validators::HtmlValidator
- Defined in:
- lib/canon/validators/html_validator.rb
Overview
Validator for HTML input
Validates HTML input (HTML4, HTML5, or XHTML) using Nokogiri. Automatically detects the HTML type and applies appropriate validation. Raises detailed ValidationError with line and column information when malformed HTML is detected.
Class Method Summary collapse
-
.validate!(input) ⇒ void
Validate HTML input.
Methods inherited from BaseValidator
Class Method Details
.validate!(input) ⇒ void
This method returns an undefined value.
Validate HTML input
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/canon/validators/html_validator.rb', line 20 def self.validate!(input) return if input.nil? || input.strip.empty? # Strip XML declaration for validation (it's not critical for parsing) cleaned_input = input.sub(/\A\s*<\?xml[^?]*\?>\s*/, "") if xhtml?(cleaned_input) validate_xhtml!(cleaned_input) else validate_html5!(cleaned_input) end end |