MCPcopy Create free account
hub / github.com/daisy/MathCAT / handle_pseudo_scripts

Method handle_pseudo_scripts

src/canonicalize.rs:2163–2214  ·  view source on GitHub ↗
(mrow: Element)

Source from the content-addressed store, hash-verified

2161 }
2162
2163 fn handle_pseudo_scripts(mrow: Element) -> Element {
2164 // from https://www.w3.org/TR/MathML3/chapter7.html#chars.pseudo-scripts
2165 static PSEUDO_SCRIPTS: phf::Set<&str> = phf_set! {
2166 "\"", "'", "*", "`", "ª", "°", "²", "³", "´", "¹", "º",
2167 "‘", "’", "“", "”", "„", "‟",
2168 "′", "″", "‴", "‵", "‶", "‷", "⁗",
2169 };
2170
2171 let mut children = mrow.children();
2172 // check to see if mrow of all psuedo scripts
2173 if children.iter().all(|&child| {
2174 let child = as_element(child);
2175 name(&child) == "mo" && PSEUDO_SCRIPTS.contains(as_text(child))
2176 }) {
2177 let parent = mrow.parent().unwrap().element().unwrap(); // must exist
2178 let is_first_child = mrow.preceding_siblings().is_empty();
2179 if is_first_child {
2180 return mrow; // FIX: what should happen
2181 }
2182 if crate::xpath_functions::IsNode::is_scripted(&parent) {
2183 return mrow; // already in a script position
2184 }
2185 if name(&parent) == "mrow" {
2186 mrow.set_attribute_value("data-pseudo-script", "true");
2187 return handle_pseudo_scripts(parent);
2188 } else {
2189 return mrow; // FIX: what should happen?
2190 }
2191 }
2192
2193 let mut i = 1;
2194 let mut found = false;
2195 while i < children.len() {
2196 let child = as_element(children[i]);
2197 if (name(&child) == "mo" && PSEUDO_SCRIPTS.contains(as_text(child))) ||
2198 child.attribute("data-pseudo-script").is_some() {
2199 let msup = create_mathml_element(&child.document(), "msup");
2200 msup.set_attribute_value(CHANGED_ATTR, ADDED_ATTR_VALUE);
2201 msup.append_child(children[i-1]);
2202 msup.append_child(child);
2203 children[i-1] = ChildOfElement::Element(msup);
2204 children.remove(i);
2205 found = true;
2206 } else {
2207 i += 1;
2208 }
2209 }
2210 if found {
2211 mrow.replace_children(children)
2212 }
2213 return mrow;
2214 }
2215
2216 fn handle_convert_to_mmultiscripts(children: &mut Vec<ChildOfElement>) {
2217 let mut i = 0;

Callers

nothing calls this directly

Calls 6

as_elementFunction · 0.85
nameFunction · 0.85
as_textFunction · 0.85
create_mathml_elementFunction · 0.85
is_emptyMethod · 0.80
lenMethod · 0.80

Tested by

no test coverage detected