pub struct Selector(/* private fields */);Expand description
Basic selector. It follows the
CSS selector
standard, but not all rules are supported now. Please refer
to Selector::from.
Implementations§
Source§impl Selector
impl Selector
Sourcepub fn matches(&self, element: &Element) -> bool
pub fn matches(&self, element: &Element) -> bool
Check if the element matches the selector.
use html_editor::{Node, Element};
use html_editor::operation::*;
let element: Element = Element::new(
"div",
vec![("id", "app")],
vec![Node::Text("Hello World!".to_string())],
);
let selector = Selector::from("div#app");
assert_eq!(selector.matches(&element), true);Trait Implementations§
Source§impl From<&str> for Selector
impl From<&str> for Selector
Source§fn from(selector: &str) -> Self
fn from(selector: &str) -> Self
Generate a selector from given string, following the CSS selector standard.
Not all rules are supported. Below shows the rules currently supported:
use html_editor::operation::Selector;
// Type Selector
Selector::from("span");
// Class selector
Selector::from(".class");
// ID selector
Selector::from("#id");
// Selector list
Selector::from("h1, h2");
// Compound selector
Selector::from("input.username");
// Disallowed input that may cause unexpected result
Selector::from("div span");
Selector::from("a[target=_blank]");Auto Trait Implementations§
impl Freeze for Selector
impl RefUnwindSafe for Selector
impl Send for Selector
impl Sync for Selector
impl Unpin for Selector
impl UnwindSafe for Selector
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more