///|
test "readme selector descendants only" {
let div = @dom.element("div", attrs={ "id": Some("r") }, children=[
@dom.element("p", attrs={ "class": Some("hit") }),
@dom.element("p"),
])
debug_inspect(
(
@selector.query(div, "p").length(), // descendants
@selector.query(div, "#r").length(), // root excluded
@selector.matches(div, "#r"), // root included
),
content=(
#|(2, 0, true)
),
)
}///|
test "readme selector grammar" {
let div = @dom.element("div", children=[
@dom.element("p", attrs={ "class": Some("intro lede") }, children=[
@dom.text("first"),
]),
@dom.element("p", attrs={ "class": Some("intro") }, children=[
@dom.text("second"),
]),
@dom.element("p", children=[@dom.text("third")]),
])
// Tag, class, attribute presence, compound (tag+class), and list.
debug_inspect(
(
@selector.query(div, "p").length(),
@selector.query(div, ".intro").length(),
@selector.query(div, "[class]").length(),
@selector.query(div, "p.intro.lede").length(),
@selector.query(div, "p.lede, p:not(.intro)").length(),
),
content=(
#|(3, 2, 2, 1, 2)
),
)
}///|
test "readme is_valid" {
debug_inspect(
(@selector.is_valid("p.intro"), @selector.is_valid("p..bad")),
content=(
#|(true, false)
),
)
}match @selector.matches_with_limits(node, sel, @selector.SelectorLimits())
catch {
err => log("rejected: \{err}")
}fn SelectorLimits::SelectorLimits(max_match_depth? : Int, max_length? : Int, max_list_items? : Int, max_compound_simple_selectors? : Int, max_complex_selector_parts? : Int, max_parse_depth? : Int, max_match_steps? : Int, max_match_bytes? : Int) -> SelectorLimits#deprecated("implicit derived-impl promotion; call the trait method directly")
fn SelectorLimits::equal(SelectorLimits, SelectorLimits) -> Bool#deprecated("implicit derived-impl promotion; call the trait method directly")
fn SelectorLimits::not_equal(x : SelectorLimits, y : SelectorLimits) -> Bool#deprecated("implicit derived-impl promotion; call the trait method directly")
fn SelectorLimits::to_repr(SelectorLimits) -> Reprfn is_valid(selector : StringView) -> Boolfn matches_with_limits(node : Node, selector : StringView, limits : SelectorLimits) -> Bool raise HtmlErrorInstall
Download zipMoonBit HTML parser and sanitizer ported from JustHTML.
Dependencies