Return the root of the ancestor tree if we are at the left/right side of a path from that to 'element'
(element: Element<'a>, use_left_side: bool, stop_node_name: &str)
| 977 | impl EdgeNode { |
| 978 | // Return the root of the ancestor tree if we are at the left/right side of a path from that to 'element' |
| 979 | fn edge_node<'a>(element: Element<'a>, use_left_side: bool, stop_node_name: &str) -> Option<Element<'a>> { |
| 980 | let element_name = name(&element); |
| 981 | if element_name == "math" { |
| 982 | return Some(element); |
| 983 | }; |
| 984 | |
| 985 | let parent = element.parent().unwrap().element().unwrap(); // there is always a "math" node |
| 986 | let parent_name = name(&parent); |
| 987 | |
| 988 | // first check to see if we have the special case of punctuation as last child of math/mrow element |
| 989 | // it only matters if we are looking at the right edge |
| 990 | |
| 991 | // debug!("EdgeNode: there are {} preceding siblings",element.preceding_siblings().len() ); |
| 992 | if use_left_side && !element.preceding_siblings().is_empty() {// not at left side |
| 993 | return None; |
| 994 | }; |
| 995 | |
| 996 | if !use_left_side && !element.following_siblings().is_empty() { // not at right side |
| 997 | // check for the special case that the parent is an mrow and the grandparent is <math> and we have punctuation |
| 998 | let grandparent = parent.parent().unwrap().element().unwrap(); |
| 999 | if name(&grandparent) == "math" && |
| 1000 | parent_name == "mrow" && parent.children().len() == 2 { // right kind of mrow |
| 1001 | let text = get_text_from_element( as_element(parent.children()[1]) ); |
| 1002 | if text == "," || text == "." || text == ";" || text == "?" { |
| 1003 | return Some(grandparent); |
| 1004 | } |
| 1005 | } |
| 1006 | return None; |
| 1007 | }; |
| 1008 | |
| 1009 | // at an edge -- check to see the parent is desired root |
| 1010 | if parent_name == stop_node_name || |
| 1011 | (stop_node_name == "2D" && MATHML_2D_NODES.contains(name(&parent))) { |
| 1012 | return Some(parent); |
| 1013 | }; |
| 1014 | |
| 1015 | // debug!("EdgeNode: recurse to {}", parent_name); |
| 1016 | return EdgeNode::edge_node(parent, use_left_side, stop_node_name) |
| 1017 | } |
| 1018 | } |
| 1019 | |
| 1020 | // EdgeNode(node, "left"/"right", stopNodeName) |
nothing calls this directly
no test coverage detected