astral-html 0.0.2

A high-performance HTML parser designed for document traversal.
Documentation

astral-html

Crates.io

A high-performance HTML parser designed for document traversal.

[!WARNING]

This README was written by a human, but all code changes, PR summaries, and additional documentation were authored entirely by GPT-6 Astra in Codex.

Example usage

Use Document to traverse elements and extract text and attributes, or Reader to process HTML as a stream of tokens.

For example, to extract links from a document:

use astral_html::Document;

let source = r#"<a href="/guide">Read the guide</a>"#;
let document = Document::parse(source)?;

for element in document.elements().filter(|element| element.is("a")) {
    if let Some(href) = element.attribute("href") {
        println!("{}: {}", element.text(), href.value());
    }
}

To extract link URLs without building a document, use Reader:

use astral_html::{Reader, Token};

let source = r#"<a href="/guide">Read the guide</a>"#;

for token in Reader::new(source) {
    if let Token::StartTag(tag) = token
        && tag.name == "a"
        && let Some(href) = tag.attributes.iter().find(|attr| attr.name == "href")
    {
        println!("{}", href.value());
    }
}

License

astral-html is licensed under either of

at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in astral-html by you, as defined in the Apache-2.0 license, shall be dually licensed as above, without any additional terms or conditions.