Skip to content
This repository has been archived by the owner on Aug 26, 2023. It is now read-only.

Commit

Permalink
Merge pull request #171 from rubys/flavorjones-check-for-html5-alread…
Browse files Browse the repository at this point in the history
…y-defined

feat: Nokogumbo detects Nokogiri's HTML5 API
  • Loading branch information
flavorjones authored Mar 17, 2021
2 parents 7a6c04d + dc68896 commit a97e317
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ jobs:
if: matrix.os == 'ubuntu'
run: sudo apt-get install -y ragel

- name: Install ragel
if: matrix.os == 'macos'
run: brew install ragel

- name: Test Gumbo and gem packaging
shell: bash
run: ./scripts/ci-package-test.sh
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
32 changes: 21 additions & 11 deletions lib/nokogumbo.rb
Original file line number Diff line number Diff line change
@@ -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'

0 comments on commit a97e317

Please sign in to comment.