Class: Canon::Formatters::HtmlFormatter

Inherits:
HtmlFormatterBase show all
Defined in:
lib/canon/formatters/html_formatter.rb

Overview

HTML formatter for HTML 4/5 and XHTML

Constant Summary

Constants inherited from HtmlFormatterBase

Canon::Formatters::HtmlFormatterBase::BLOCK_ELEMENTS, Canon::Formatters::HtmlFormatterBase::WHITESPACE_SENSITIVE_ELEMENTS

Class Method Summary collapse

Methods inherited from HtmlFormatterBase

canonicalize, format

Class Method Details

.parse(html) ⇒ Nokogiri::HTML::Document, Nokogiri::XML::Document

Parse HTML into a Nokogiri document

Parameters:

  • html (String)

    HTML document to parse

Returns:

  • (Nokogiri::HTML::Document, Nokogiri::XML::Document)

    Parsed HTML or XML document



16
17
18
19
20
21
22
23
24
25
# File 'lib/canon/formatters/html_formatter.rb', line 16

def self.parse(html)
  # Validate before parsing
  Canon::Validators::HtmlValidator.validate!(html)

  if xhtml?(html)
    Nokogiri::XML(html)
  else
    Nokogiri::HTML5(html)
  end
end