ratex_parser/functions/
htmlmathml.rs1use std::collections::HashMap;
2
3use crate::error::{ParseError, ParseResult};
4use crate::functions::{define_function_full, ArgType, FunctionContext, FunctionSpec};
5use crate::parse_node::ParseNode;
6
7pub fn register(map: &mut HashMap<&'static str, FunctionSpec>) {
8 define_function_full(
9 map,
10 &["\\html@mathml"],
11 "htmlmathml",
12 2,
13 0,
14 None,
15 false,
16 true,
17 true,
18 false,
19 false,
20 handle_htmlmathml,
21 );
22
23 define_function_full(
24 map,
25 &["\\htmlStyle"],
26 "html",
27 2,
28 0,
29 Some(vec![ArgType::Raw, ArgType::Original]),
30 false,
31 true,
32 true,
33 false,
34 false,
35 handle_htmlstyle,
36 );
37}
38
39fn handle_htmlmathml(
40 ctx: &mut FunctionContext,
41 args: Vec<ParseNode>,
42 _opt_args: Vec<Option<ParseNode>>,
43) -> ParseResult<ParseNode> {
44 let html = ParseNode::ord_argument(args[0].clone());
45 let mathml = ParseNode::ord_argument(args[1].clone());
46
47 Ok(ParseNode::HtmlMathMl {
48 mode: ctx.parser.mode,
49 html,
50 mathml,
51 loc: None,
52 })
53}
54
55fn handle_htmlstyle(
56 ctx: &mut FunctionContext,
57 args: Vec<ParseNode>,
58 _opt_args: Vec<Option<ParseNode>>,
59) -> ParseResult<ParseNode> {
60 let mut args = args.into_iter();
61 let style = match args.next() {
62 Some(ParseNode::Raw { string, .. }) => string,
63 _ => return Err(ParseError::msg("Expected raw style for \\htmlStyle")),
64 };
65 let body = ParseNode::ord_argument(args.next().unwrap());
66 let mut attributes = HashMap::new();
67 attributes.insert("style".to_string(), style);
68
69 Ok(ParseNode::Html {
70 mode: ctx.parser.mode,
71 attributes,
72 body,
73 loc: None,
74 })
75}