node_html_parser/css_select/
mod.rs1pub mod attributes;
2pub mod compile;
3pub mod convert;
4pub mod general;
5pub mod helpers;
6pub mod legacy;
7pub mod types;
8
9use crate::{css_select::compile::compile_token as compile_token_impl, dom::element::HTMLElement};
10use types::{Adapter, CompiledQuery, Options};
11
12pub fn select_all<'a>(selector: &str, root: &'a HTMLElement) -> Vec<&'a HTMLElement> {
13 legacy::query_selector_all(root, selector)
14}
15
16pub fn select_one<'a>(selector: &str, root: &'a HTMLElement) -> Option<&'a HTMLElement> {
17 select_all(selector, root).into_iter().next()
18}
19
20pub fn is<'a>(elem: &'a HTMLElement, selector: &str, root: &'a HTMLElement) -> bool {
21 let ptr = elem as *const HTMLElement;
23 select_all(selector, root)
24 .into_iter()
25 .any(|e| std::ptr::eq(e as *const HTMLElement, ptr))
26}
27
28pub fn prepare_context<'a>(root: &'a HTMLElement) -> Vec<&'a HTMLElement> {
29 vec![root]
30}
31
32pub fn compile<'a, A: Adapter>(
35 selector: &str,
36 options: &Options<A>,
37 root: &'a HTMLElement,
38) -> CompiledQuery<'a, A> {
39 compile_token_impl::<A>(selector, options, root)
40}
41
42pub fn compile_token<'a, A: Adapter>(
43 selector: &str,
44 options: &Options<A>,
45 root: &'a HTMLElement,
46) -> CompiledQuery<'a, A> {
47 compile_token_impl::<A>(selector, options, root)
48}
49
50pub fn compile_unsafe<'a, A: Adapter>(
51 selector: &str,
52 options: &Options<A>,
53 root: &'a HTMLElement,
54) -> CompiledQuery<'a, A> {
55 compile_token_impl::<A>(selector, options, root)
56}
57
58pub fn compile_experimental<'a, A: Adapter + 'a>(
60 selector: &str,
61 _options: &Options<A>,
62 adapter: &'a A,
63) -> CompiledQuery<'a, A> {
64 crate::css_select::compile::compile_internal_new::<A>(selector, adapter)
66}