Nokogumbo - a Nokogiri interface to the Gumbo HTML5 parser.
require 'nokogumbo' doc = ::(string)
An experimental fragment method is also provided. While not HTML5 compliant, it may be useful:
require 'nokogumbo' doc = ::.(string)
Because HTML is often fetched via the web, a convenience interface to HTTP get is also provided:
require 'nokogumbo' doc = ::.(uri)
require 'nokogumbo' puts ::.('http://nokogiri.org').search('ol li').text
.to_html instead of
.to_s when parsing and serializing multiple times
require 'nokogumbo' ::.(::.('<div></div> a').to_html).to_html
Nokogiri::HTML5.fragmentfunction takes a string and parses it as a HTML5 document. The
<body>elements are removed from this document, and any children of these elements that remain are returned as a
Nokogiri::HTML5.parsefunction takes a string and passes it to the
gumbo_parse_with_optionsmethod, using the default options. The resulting Gumbo parse tree is then walked.
- If the necessary Nokogiri and libxml2 headers can be found at installation time then an xmlDoc tree is produced and a single Nokogiri Ruby object is constructed to wrap the xmlDoc structure. Nokogiri only produces Ruby objects as necessary, so all searching is done using the underlying libxml2 libraries.
- If the necessary headers are not present at installation time, then Nokogiri Ruby objects are created for each Gumbo node. Other than memory usage and CPU time, the results should be equivalent.
Nokogiri::HTML5.getfunction takes care of following redirects, https, and determining the character encoding of the result, based on the rules defined in the HTML5 specification for doing so.
Instead of uppercase element names, lowercase element names are produced.
Instead of returning
unknownas the element name for unknown tags, the original tag name is returned verbatim.
If the Gumbo HTML5 parser is not already installed, the source for the parser will be downloaded and compiled into the Gem itself.
git clone --recursive https://github.com/rubys/nokogumbo.git cd nokogumbo bundle install rake gem gem install pkg/nokogumbo*.gem
- ruby-gumbo - a ruby binding for the Gumbo HTML5 parser.