A Rust library for parsing, manipulating, and querying HTML documents using CSS selectors.
This is a fork of Kuchiki (朽木) by way of Brave's Kuchikiki fork. The original Kuchiki is now unmaintained.
Brik is a building block for HTML manipulation - simple, solid, and stackable.
This fork maintains compatibility with current servo crates (html5ever, selectors, etc.) and provides ongoing updates. See the Changelog for version history and updates.
- ✨ Full HTML5 parsing via html5ever
- 🎯 CSS selector queries via selectors
- 🌳 Tree manipulation - append, prepend, insert, detach nodes
- 🔍 Node inspection - traverse ancestors, siblings, descendants
- 📝 Serialization - convert trees back to HTML
- 🔖 Namespace support - optional XML/SVG namespace handling (not enabled by default)
- 🛡️ Optional safe mode - build without unsafe code
⚠️ Status: Alpha - Passes all tests but not yet recommended for production use.
Add this to your Cargo.toml:
[dependencies]
brik = "0.10.0"This migration applies to both Kuchiki and Kuchikiki.
[dependencies]
brik = "0.10.0" # Changed from "kuchiki" or "kuchikiki"Update your code:
use brik::parse_html; // Changed from kuchiki or kuchikiki
use brik::traits::*;use brik::parse_html;
use brik::traits::*;
// Parse HTML and query with CSS selectors
let document = parse_html().one("<p class='greeting'>Hello, world!</p>");
let greeting = document.select_first(".greeting").unwrap();
println!("{}", greeting.text_contents());For more detailed examples, see the examples directory.
By default, brik uses unsafe code for performance. To build without any unsafe blocks:
[dependencies]
brik = { version = "0.10.0", features = ["safe"] }Or via command line:
cargo build --features safe
cargo test --features safeNote: This only affects brik's code, not its dependencies.
XML/SVG namespace support is available via the namespaces feature:
[dependencies]
brik = { version = "0.10.0", features = ["namespaces"] }This enables:
- Namespace-aware CSS selectors (e.g.,
svg|rect,[xlink|href]) - Element namespace inspection methods (
namespace_uri(),prefix()) - Namespace-aware attribute methods (
get_ns(),insert_ns(), etc.) - Filtering elements by namespace
Or via command line:
cargo build --features namespaces
cargo test --features namespaces
cargo run --example namespaces --features namespacesNote: HTML-only users can omit this feature to reduce binary size.
Full API documentation is available at docs.rs/brik.
Run examples with:
cargo run --example quickstart
cargo run --example find_matchesSee the examples directory for all available examples.
See the Security Policy for information on reporting vulnerabilities.
This project builds on the work of:
- Original Kuchiki library: kuchiki-rs/kuchiki by Simon Sapin
- Brave fork: brave/kuchikiki maintained by the Brave Authors and Ralph Giles
Brik is maintained by Adam Mill (@theroyalwhee0)
Contributions are welcome! Please see our Contributing Guidelines and Code of Conduct before submitting a Pull Request.
Licensed under the MIT license. See LICENSE for details.