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
- 🛡️ 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:
[]
= "0.8"
Migrating from Kuchiki or Kuchikiki
This migration applies to both Kuchiki and Kuchikiki.
[]
= "0.8" # Changed from "kuchiki" or "kuchikiki"
Update your code:
use parse_html; // Changed from kuchiki or kuchikiki
use *;
Quick Start
use parse_html;
use *;
// Parse HTML and query with CSS selectors
let document = parse_html.one;
let greeting = document.select_first.unwrap;
println!;
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:
[]
= { = "0.8", = ["safe"] }
Or via command line:
Note: This only affects brik's code, not its dependencies.
Namespace Support
XML/SVG namespace support is available via the namespaces feature:
[]
= { = "0.8", = ["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:
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:
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.