@@ -10,9 +10,11 @@ use swc_core::ecma::visit::{VisitMut, VisitMutWith};
1010
1111use crate :: Diagnostic ;
1212use crate :: config:: {
13- NativeCollectionConfig , NativeMdxConfig , NativeMediaConfig , apply_schema_defaults_and_validate,
13+ NativeCollectionConfig , NativeMathConfig , NativeMdxConfig , NativeMediaConfig ,
14+ apply_schema_defaults_and_validate,
1415} ;
1516use crate :: hast:: { remove_table_line_breaks, rewrite_media} ;
17+ use crate :: math:: replace_math;
1618
1719#[ derive( Debug , serde:: Serialize ) ]
1820#[ serde( rename_all = "camelCase" ) ]
@@ -89,11 +91,17 @@ pub fn prepare_mdx(
8991 file : & str ,
9092 body : & str ,
9193 config : & NativeMdxConfig ,
94+ math : & NativeMathConfig ,
9295 highlight : bool ,
9396 root : & Path ,
9497 media : & NativeMediaConfig ,
9598) -> Result < PreparedMdx , Vec < Diagnostic > > {
96- let options = mdx_options ( file, config) ;
99+ let mut options = mdx_options ( file, config) ;
100+ if math. enabled {
101+ options. parse . constructs . math_flow = true ;
102+ options. parse . constructs . math_text = true ;
103+ options. parse . math_text_single_dollar = math. single_dollar ;
104+ }
97105 let mut mdast = mdxjs:: mdast_util_from_mdx ( body, & options)
98106 . map_err ( |error| vec ! [ mdx_diagnostic( file, error) ] ) ?;
99107 let reading_words = reading_units ( & mdast) ;
@@ -105,6 +113,7 @@ pub fn prepare_mdx(
105113 apply_hard_breaks ( & mut mdast) ;
106114 }
107115 let mut tree = mdxjs:: mdast_util_to_hast ( & mdast) ;
116+ replace_math ( & mut tree, file, math) ?;
108117 remove_table_line_breaks ( & mut tree) ;
109118 let media = rewrite_media ( & mut tree, root, Path :: new ( file) , media) ?;
110119
@@ -378,7 +387,9 @@ mod tests {
378387 use mdxjs:: hast:: Node ;
379388 use serde_json:: json;
380389
381- use crate :: config:: { MediaMissing , NativeCollectionConfig , NativeMdxConfig , NativeMediaConfig } ;
390+ use crate :: config:: {
391+ MediaMissing , NativeCollectionConfig , NativeMathConfig , NativeMdxConfig , NativeMediaConfig ,
392+ } ;
382393
383394 use super :: { finish_mdx, parse_frontmatter, prepare_mdx} ;
384395
@@ -440,6 +451,7 @@ mod tests {
440451 "/project/hello.mdx" ,
441452 source,
442453 & options,
454+ & NativeMathConfig :: default ( ) ,
443455 false ,
444456 std:: path:: Path :: new ( "/project" ) ,
445457 & NativeMediaConfig :: default ( ) ,
@@ -478,6 +490,7 @@ mod tests {
478490 "/project/table.mdx" ,
479491 source,
480492 & options,
493+ & NativeMathConfig :: default ( ) ,
481494 false ,
482495 std:: path:: Path :: new ( "/project" ) ,
483496 & NativeMediaConfig :: default ( ) ,
@@ -501,6 +514,7 @@ mod tests {
501514 "/project/hello.mdx" ,
502515 source,
503516 & options,
517+ & NativeMathConfig :: default ( ) ,
504518 false ,
505519 std:: path:: Path :: new ( "/project" ) ,
506520 & NativeMediaConfig :: default ( ) ,
@@ -540,6 +554,7 @@ mod tests {
540554 file. to_str ( ) . unwrap ( ) ,
541555 source,
542556 & options,
557+ & NativeMathConfig :: default ( ) ,
543558 false ,
544559 & root,
545560 & media,
@@ -585,6 +600,7 @@ mod tests {
585600 "/project/content/post.mdx" ,
586601 "" ,
587602 & options,
603+ & NativeMathConfig :: default ( ) ,
588604 false ,
589605 std:: path:: Path :: new ( "/project" ) ,
590606 & media,
0 commit comments