logicaffeine_web/ui/components/mixed_text.rs
1//! Mixed text and LaTeX rendering component.
2//!
3//! Renders text that may contain embedded LaTeX expressions.
4//! Automatically parses `$...$` (inline) and `$$...$$` (display) markers.
5//!
6//! # Props
7//!
8//! - `content` - Text containing optional LaTeX markers
9//!
10//! # Example
11//!
12//! ```no_run
13//! # use dioxus::prelude::*;
14//! # use logicaffeine_web::ui::components::mixed_text::MixedText;
15//! # fn Example() -> Element {
16//! rsx! {
17//! MixedText { content: "The formula $x + y$ equals...".to_string() }
18//! }
19//! # }
20//! ```
21
22use dioxus::prelude::*;
23use super::katex::{KatexSpan, TextPart, parse_latex_in_text};
24
25#[component]
26pub fn MixedText(content: String) -> Element {
27 let parts = parse_latex_in_text(&content);
28
29 rsx! {
30 span { class: "mixed-text",
31 for (i, part) in parts.iter().enumerate() {
32 match part {
33 TextPart::Plain(text) => rsx! {
34 span { key: "{i}", "{text}" }
35 },
36 TextPart::Latex { content, display } => rsx! {
37 KatexSpan { key: "{i}", latex: content.clone(), display: *display }
38 },
39 }
40 }
41 }
42 }
43}