rubys / nokogumbo

A Nokogiri interface to the Gumbo HTML5 parser.
Apache License 2.0
186 stars 114 forks source link

feat: Nokogumbo detects Nokogiri's HTML5 API #171

Closed flavorjones closed 3 years ago

flavorjones commented 3 years ago

What are you trying to accomplish?

A future version of Nokogiri will provide Nokogumbo's API (see https://github.com/sparklemotion/nokogiri/issues/2204). This change will allow Nokogumbo to detect whether Nokogiri provides the HTML5 API and whether to use Nokogiri's implementation or Nokogumbo's implementation.

This was discussed in-depth at #170.

What approach did you choose and why?

Some contractual assumptions I'm making about Nokogiri:

This change checks for the existence of Nokogiri::HTML5, Nokogiri::Gumbo, and an expected singleton method on each. We could do a more- or less-thorough check here.

This change also provides an "escape hatch" using an environment variable NOKOGUMBO_IGNORE_NOKOGIRI_HTML5 which can be set to force Nokogumbo to use its own implementation. This escape hatch might be unnecessary, but this change is invasive enough to make me want to be cautious.

Nokogumbo will emit a single warning message at require-time when it is uses Nokogiri's implementation. This message points users to https://github.com/sparklemotion/nokogiri/issues/2205 which will explain what's going on and help people migrate their applications (but is an empty placeholder right now).

What should reviewers focus on?

Please check my assumptions and provide feedback on the decisions made.