diff --git a/inline/src/element/formatting/scoped.rs b/inline/src/element/formatting/scoped.rs index 6103b3ed..ce535936 100644 --- a/inline/src/element/formatting/scoped.rs +++ b/inline/src/element/formatting/scoped.rs @@ -11,12 +11,9 @@ macro_rules! scoped_parser { pub(crate) fn $fn_name<'slice, 'input>( mut parser: InlineParser<'slice, 'input>, ) -> (InlineParser<'slice, 'input>, Option) { - let open_token_opt = parser.iter.peeking_next(|_| true); - if open_token_opt.is_none() { + let Some(open_token) = parser.iter.peeking_next(|_| true) else { return (parser, None); - } - - let open_token = open_token_opt.expect("Checked above to be not None."); + }; // No need to check for correct opening format, because parser is only assigned for valid opening tokens. if parser.iter.peek_kind().map_or(true, |t| t.is_space()) { @@ -33,6 +30,7 @@ macro_rules! scoped_parser { !matcher.prev_is_space() && matcher.consumed_matches(&[InlineTokenKind::$kind.into()]) }))); + scoped_parser.context.flags.allow_implicits = false; scoped_parser.context.flags.keep_whitespaces = true; scoped_parser.context.flags.logic_only = true; diff --git a/inline/src/parser.rs b/inline/src/parser.rs index da8b3a4a..ac8bb30c 100644 --- a/inline/src/parser.rs +++ b/inline/src/parser.rs @@ -128,8 +128,10 @@ impl<'slice, 'input> InlineParser<'slice, 'input> { if let Some(parser_fn) = parser_fn_opt { let checkpoint = parser.iter.checkpoint(); + let (updated_parser, inline_opt) = parser_fn(parser); parser = updated_parser; + match inline_opt { Some(inline) => { inlines.push(inline); diff --git a/render/Cargo.toml b/render/Cargo.toml index 29345713..b8992ffe 100644 --- a/render/Cargo.toml +++ b/render/Cargo.toml @@ -20,6 +20,7 @@ unimarkup-inline = { path = "../inline/", version = "0" } unimarkup-parser = { path = "../parser/", version = "0" } syntect = "5.0" spreadsheet-ods = "0.17.0" +mathemascii = "0.4.0" serde.workspace = true serde_json.workspace = true -serde_yaml.workspace = true \ No newline at end of file +serde_yaml.workspace = true diff --git a/render/src/html/render.rs b/render/src/html/render.rs index 2bad88d7..d56f77e0 100644 --- a/render/src/html/render.rs +++ b/render/src/html/render.rs @@ -6,7 +6,7 @@ use unimarkup_inline::element::{ Underline, Verbatim, }, textbox::{hyperlink::Hyperlink, TextBox}, - InlineElement, + Inline, InlineElement, }; use unimarkup_parser::elements::indents::{BulletList, BulletListEntry}; @@ -294,16 +294,28 @@ impl Renderer for HtmlRenderer { fn render_inline_math( &mut self, math: &Math, - context: &Context, + _context: &Context, ) -> Result { - // TODO: use proper math rendering once supported - let inner = self.render_nested_inline(math.inner(), context)?; + // TODO: resolve logic inlines before parsing math. + let content_str: String = math + .inner() + .iter() + .filter_map(|i| match i { + Inline::Plain(p) => Some(p.content().clone()), + _ => None, + }) + .collect(); - Ok(Html::nested( - HtmlTag::Span, - HtmlAttributes::default(), - inner, - )) + let math = mathemascii::render_mathml(mathemascii::parse(&content_str)); + + Ok(Html::with_body(HtmlBody { + elements: vec![HtmlElement { + tag: HtmlTag::PlainContent, + attributes: HtmlAttributes::default(), + content: Some(math), + }] + .into(), + })) } fn render_plain(