A fast, lossless HTML parser with source offsets, CSS selectors, and an optional mutable tree
moon add justjavac/html///|
test "parse and query HTML" {
let doc = @html.parse(
"<head><title>Hi & bye</title><link rel=canonical href=\"/\"></head>",
)
inspect(doc.find("head > title").unwrap().text(), content="Hi & bye")
assert_eq(
doc.find("link[rel=canonical]").unwrap().get_attr("href"),
Some("/"),
)
let title = doc.find("title").unwrap()
assert_eq(doc.position(title.start()), { line: 1, column: 7, })
inspect(title.stringify(), content="<title>Hi & bye</title>")
}pub trait Stringify {
fn stringify(Self) -> String
}pub suberror SelectorError {
InvalidSelector(String)
}pub struct Comment {
// private fields
}pub struct Directive {
// private fields
}pub struct Document {
// private fields
}pub struct Element {
// private fields
}pub struct Selector {
// private fields
}pub struct Text {
// private fields
}Install
Download zipA fast, lossless HTML parser with source offsets, CSS selectors, and an optional mutable tree