Class: Canon::Validators::HtmlValidator

Inherits:
BaseValidator show all
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

Methods inherited from BaseValidator

extract_location

Class Method Details

.validate!(input) ⇒ void

This method returns an undefined value.

Validate HTML input

Parameters:

  • input (String)

    The HTML string to validate

Raises:



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