use super::{TexElement, TexParser};
impl TexParser {
pub(super) fn parse_text(&mut self) -> Option<TexElement> {
let mut text = String::new();
while self.position < self.content.len() {
let remaining = &self.content[self.position..];
if remaining.starts_with('\\') || remaining.starts_with("\n\n") || remaining.starts_with('}') {
break;
}
if remaining.starts_with('$') {
self.position += 1;
if self.position < self.content.len() && self.content[self.position..].starts_with('$') {
self.position -= 1;
break;
}
let math_content = self.read_until('$');
self.position += 1;
text.push_str(&format!("${}$", math_content));
} else if let Some(ch) = remaining.chars().next() {
text.push(ch);
self.position += ch.len_utf8();
}
}
if text.is_empty() {
None
} else {
Some(TexElement::Text(text.trim().to_string()))
}
}
}