MCPcopy Create free account
hub / github.com/d0iasm/saba / get_target_element_node

Function get_target_element_node

core/src/renderer/dom/api.rs:38–58  ·  view source on GitHub ↗

TODO: return an array of Node instead of one Node.

(
    node: Option<Rc<RefCell<Node>>>,
    element_kind: ElementKind,
)

Source from the content-addressed store, hash-verified

36
37// TODO: return an array of Node instead of one Node.
38pub fn get_target_element_node(
39 node: Option<Rc<RefCell<Node>>>,
40 element_kind: ElementKind,
41) -> Option<Rc<RefCell<Node>>> {
42 match node {
43 Some(n) => {
44 if n.borrow().kind()
45 == NodeKind::Element(Element::new(&element_kind.to_string(), Vec::new()))
46 {
47 return Some(n.clone());
48 }
49 let result1 = get_target_element_node(n.borrow().first_child(), element_kind);
50 let result2 = get_target_element_node(n.borrow().next_sibling(), element_kind);
51 if result1.is_none() {
52 return result2;
53 }
54 result1
55 }
56 None => None,
57 }
58}
59
60pub fn get_style_content(root: Rc<RefCell<Node>>) -> String {
61 let style_node = match get_target_element_node(Some(root), ElementKind::Style) {

Callers 3

newMethod · 0.85
get_style_contentFunction · 0.85
get_js_contentFunction · 0.85

Calls 5

ElementClass · 0.85
to_stringMethod · 0.80
kindMethod · 0.45
first_childMethod · 0.45
next_siblingMethod · 0.45

Tested by

no test coverage detected