4 releases
| 0.10.0 | Nov 11, 2025 |
|---|---|
| 0.9.2 | Nov 8, 2025 |
| 0.9.1 | Oct 25, 2025 |
| 0.9.0 | Oct 24, 2025 |
#800 in Template engine
385KB
6.5K
SLoC
Brik
A Rust library for parsing, manipulating, and querying HTML documents using CSS selectors.
About
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.
Features
- ✨ 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
Installation
⚠️ Status: Alpha - Passes all tests but not yet recommended for production use.
Add this to your Cargo.toml:
[dependencies]
brik = "0.10.0"
Migrating from Kuchiki or Kuchikiki
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::*;
Quick Start
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.
Feature Flags
Safe Mode
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 safe
Note: This only affects brik's code, not its dependencies.
Namespace Support
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 namespaces
Note: HTML-only users can omit this feature to reduce binary size.
Documentation
Full API documentation is available at docs.rs/brik.
Examples
Run examples with:
cargo run --example quickstart
cargo run --example find_matches
See the examples directory for all available examples.
Security
See the Security Policy for information on reporting vulnerabilities.
Credits
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)
Contributing
Contributions are welcome! Please see our Contributing Guidelines and Code of Conduct before submitting a Pull Request.
License
Licensed under the MIT license. See LICENSE for details.
Dependencies
~3–4.5MB
~88K SLoC