Speak the MathML If 'nav_node_id' is not an empty string, then the element with that id will have [[...]] around it
(rules: &'static std::thread::LocalKey<RefCell<SpeechRules>>, mathml: Element, nav_node_id: &str)
| 100 | /// Speak the MathML |
| 101 | /// If 'nav_node_id' is not an empty string, then the element with that id will have [[...]] around it |
| 102 | fn speak_rules(rules: &'static std::thread::LocalKey<RefCell<SpeechRules>>, mathml: Element, nav_node_id: &str) -> Result<String> { |
| 103 | SpeechRules::update()?; |
| 104 | rules.with(|rules| { |
| 105 | rules.borrow_mut().read_files()?; |
| 106 | let rules = rules.borrow(); |
| 107 | // debug!("speak_rules:\n{}", mml_to_string(&mathml)); |
| 108 | let new_package = Package::new(); |
| 109 | let mut rules_with_context = SpeechRulesWithContext::new(&rules, new_package.as_document(), nav_node_id); |
| 110 | let mut speech_string = rules_with_context.match_pattern::<String>(mathml) |
| 111 | .chain_err(|| "Pattern match/replacement failure!")?; |
| 112 | if !nav_node_id.is_empty() { |
| 113 | // See https://github.com/NSoiffer/MathCAT/issues/174 for why we can just start the speech at the nav node |
| 114 | if let Some(start) = speech_string.find("[[") { |
| 115 | match speech_string[start+2..].find("]]") { |
| 116 | None => bail!("Internal error: looking for '[[...]]' during navigation -- only found '[[' in '{}'", speech_string), |
| 117 | Some(end) => speech_string = speech_string[start+2..start+2+end].to_string(), |
| 118 | } |
| 119 | } else { |
| 120 | bail!(NAV_NODE_SPEECH_NOT_FOUND); |
| 121 | } |
| 122 | } |
| 123 | return Ok( rules.pref_manager.borrow().get_tts() |
| 124 | .merge_pauses(remove_optional_indicators( |
| 125 | &speech_string.replace(CONCAT_STRING, "") |
| 126 | .replace(CONCAT_INDICATOR, "") |
| 127 | ) |
| 128 | .trim()) ); |
| 129 | }) |
| 130 | } |
| 131 | |
| 132 | |
| 133 | /// Converts its argument to a string that can be used in a debugging message. |
no test coverage detected