blob: 40a1990ec6dc93965e2be2484b89d492a504cd8f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
//! Mathematical formulas.
use super::prelude::*;
/// A mathematical formula.
#[derive(Debug, Hash)]
pub struct MathNode {
/// The formula.
pub formula: EcoString,
/// Whether the formula is display-level.
pub display: bool,
}
#[class]
impl MathNode {
fn construct(_: &mut Vm, args: &mut Args) -> TypResult<Template> {
Ok(Template::show(Self {
formula: args.expect("formula")?,
display: args.named("display")?.unwrap_or(false),
}))
}
}
impl Show for MathNode {
fn show(&self, vm: &mut Vm, styles: StyleChain) -> TypResult<Template> {
Ok(styles
.show(self, vm, [
Value::Str(self.formula.clone()),
Value::Bool(self.display),
])?
.unwrap_or_else(|| {
let mut template = Template::Text(self.formula.trim().into());
if self.display {
template = Template::Block(template.pack());
}
template.monospaced()
}))
}
}
|