diff --git a/CHANGELOG.md b/CHANGELOG.md index ffd109ef..87345e30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Support Mageia distros when libxml2/libxslt system libraries are install. #165 (Thank you, @pterjan!) +### Addded +- Forward-looking support for a version of Nokogiri that will provide HTML5 parsing. #171 + ### Improved - Update extconf.rb to use Nokogiri v1.11's CPPFLAGS for more reliable installation. diff --git a/lib/nokogumbo.rb b/lib/nokogumbo.rb index 262d45b9..89602af7 100644 --- a/lib/nokogumbo.rb +++ b/lib/nokogumbo.rb @@ -1,17 +1,27 @@ require 'nokogiri' -require 'nokogumbo/version' -require 'nokogumbo/html5' -require 'nokogumbo/nokogumbo' +if ((defined?(Nokogiri::HTML5) && Nokogiri::HTML5.respond_to?(:parse)) && + (defined?(Nokogiri::Gumbo) && Nokogiri::Gumbo.respond_to?(:parse)) && + !(ENV.key?("NOKOGUMBO_IGNORE_NOKOGIRI_HTML5") && ENV["NOKOGUMBO_IGNORE_NOKOGIRI_HTML5"] != "false")) + + warn "NOTE: nokogumbo: Using Nokogiri::HTML5 provided by Nokogiri. See https://github.com/sparklemotion/nokogiri/issues/2205 for more information." + + ::Nokogumbo = ::Nokogiri::Gumbo +else + require 'nokogumbo/html5' + require 'nokogumbo/nokogumbo' -module Nokogumbo - # The default maximum number of attributes per element. - DEFAULT_MAX_ATTRIBUTES = 400 + module Nokogumbo + # The default maximum number of attributes per element. + DEFAULT_MAX_ATTRIBUTES = 400 - # The default maximum number of errors for parsing a document or a fragment. - DEFAULT_MAX_ERRORS = 0 + # The default maximum number of errors for parsing a document or a fragment. + DEFAULT_MAX_ERRORS = 0 - # The default maximum depth of the DOM tree produced by parsing a document - # or fragment. - DEFAULT_MAX_TREE_DEPTH = 400 + # The default maximum depth of the DOM tree produced by parsing a document + # or fragment. + DEFAULT_MAX_TREE_DEPTH = 400 + end end + +require 'nokogumbo/version'