Module: JekyllAutoThumbnails::HtmlParser

Defined in:
lib/jekyll-auto-thumbnails/html_parser.rb

Overview

Dispatch between Nokogiri’s HTML5 and libxml2-based HTML4 parsers.

HTML5 is the default throughout the gem; HTML4 is kept as an opt-in for users who depended on libxml2’s serialization quirks (notably the injected ‘<meta http-equiv=“Content-Type”>`).

Class Method Summary collapse

Class Method Details

.parse(html, parser) ⇒ Nokogiri::HTML5::Document, Nokogiri::HTML4::Document

Parse an HTML string with the selected parser.

Parameters:

  • html (String)

    HTML source

  • parser (Symbol)

    :html5 or :html4

Returns:

  • (Nokogiri::HTML5::Document, Nokogiri::HTML4::Document)

Raises:

  • (ArgumentError)

    for an unknown parser symbol

  • (NameError)

    if :html5 is requested under JRuby (should be prevented by Configuration validation; this is a belt-and-suspenders guard)



28
29
30
31
32
33
34
35
36
37
# File 'lib/jekyll-auto-thumbnails/html_parser.rb', line 28

def parse(html, parser)
  case parser
  when :html5
    Nokogiri::HTML5.parse(html)
  when :html4
    Nokogiri::HTML(html)
  else
    raise ArgumentError, "Unknown HTML parser: #{parser.inspect}"
  end
end