#macros #parse #hooks #pass #html5ever

nightly html5ever_macros

High-performance browser-grade HTML5 parser − compiler plugins

9 releases

Uses old Rust 2015

0.2.7 Oct 17, 2016
0.2.6 Nov 10, 2015
0.2.4 Oct 2, 2015
0.2.3 Sep 22, 2015
0.1.0 Jun 15, 2015
Download history 27/week @ 2021-02-20 14/week @ 2021-02-27 18/week @ 2021-03-06 9/week @ 2021-03-13 29/week @ 2021-03-20 18/week @ 2021-03-27 18/week @ 2021-04-03 27/week @ 2021-04-10 9/week @ 2021-04-17 11/week @ 2021-05-01 9/week @ 2021-05-15 2/week @ 2021-05-22 10/week @ 2021-06-05

72 downloads per month

MIT/Apache

23KB
400 lines

html5ever

Build Status crates.io

API Documentation

html5ever is an HTML parser developed as part of the Servo project.

It can parse and serialize HTML according to the WHATWG specs (aka "HTML5"). However, there are some differences in the actual behavior currently, most of which are documented in the bug tracker. html5ever passes all tokenizer tests from html5lib-tests, with most tree builder tests outside of the unimplemented features. The goal is to pass all html5lib tests, while also providing all hooks needed by a production web browser, e.g. document.write.

Note that the HTML syntax is very similar to XML. For correct parsing of XHTML, use an XML parser (That said, many XHTML documents in the wild are serialized in an HTML-compatible form).

html5ever is written in Rust, therefore it avoids the notorious security problems that come along with using C. Being built with Rust also makes the library come with the high-grade performance you would expect from an html parser written in C. html5ever is basically a C html parser, but without needing a garbage collector or other heavy runtime processes.

Getting started in Rust

Add html5ever as a dependency in your Cargo.toml file:

[dependencies]
html5ever = "*"

You should also take a look at examples/html2html.rs, examples/print-rcdom.rs, and the API documentation.

Getting started in other languages

Bindings for Python and other languages are much desired.

Working on html5ever

To fetch the test suite, you need to run

git submodule update --init

Run cargo doc in the repository root to build local documentation under target/doc/.

Details

html5ever uses callbacks to manipulate the DOM, therefore it does not provide any DOM tree representation.

html5ever exclusively uses UTF-8 to represent strings. In the future it will support other document encodings (and UCS-2 document.write) by converting input.

The code is cross-referenced with the WHATWG syntax spec, and eventually we will have a way to present code and spec side-by-side.

html5ever builds against the official stable releases of Rust, though some optimizations are only supported on nightly releases.

Dependencies

~12KB