|
| 1 | +mod test_utils; |
1 | 2 | use markdown::{
|
2 | 3 | mdast::{List, ListItem, MdxJsxFlowElement, Node, Paragraph, Root, Text},
|
3 | 4 | to_html_with_options, to_mdast,
|
4 | 5 | unist::Position,
|
5 | 6 | Constructs, Options, ParseOptions,
|
6 | 7 | };
|
7 | 8 | use pretty_assertions::assert_eq;
|
| 9 | +use test_utils::swc::{parse_esm, parse_expression}; |
8 | 10 |
|
9 | 11 | #[test]
|
10 | 12 | fn mdx_jsx_flow_agnostic() -> Result<(), String> {
|
@@ -226,3 +228,116 @@ fn mdx_jsx_flow_essence() -> Result<(), String> {
|
226 | 228 |
|
227 | 229 | Ok(())
|
228 | 230 | }
|
| 231 | + |
| 232 | +// Flow is mostly the same as `text`, so we only test the relevant |
| 233 | +// differences. |
| 234 | +#[test] |
| 235 | +fn mdx_jsx_flow_interleaving_with_expressions() -> Result<(), String> { |
| 236 | + let mdx = Options { |
| 237 | + parse: ParseOptions::mdx(), |
| 238 | + ..Default::default() |
| 239 | + }; |
| 240 | + let swc = Options { |
| 241 | + parse: ParseOptions { |
| 242 | + constructs: Constructs::mdx(), |
| 243 | + mdx_esm_parse: Some(Box::new(parse_esm)), |
| 244 | + mdx_expression_parse: Some(Box::new(parse_expression)), |
| 245 | + ..Default::default() |
| 246 | + }, |
| 247 | + ..Default::default() |
| 248 | + }; |
| 249 | + |
| 250 | + assert_eq!( |
| 251 | + to_html_with_options("<div>\n{1}\n</div>", &mdx)?, |
| 252 | + "", |
| 253 | + "should support tags and expressions (unaware)" |
| 254 | + ); |
| 255 | + |
| 256 | + assert_eq!( |
| 257 | + to_html_with_options("<div>\n{'}'}\n</div>", &swc)?, |
| 258 | + "", |
| 259 | + "should support tags and expressions (aware)" |
| 260 | + ); |
| 261 | + |
| 262 | + assert_eq!( |
| 263 | + to_html_with_options("x<em>{1}</em>", &swc)?, |
| 264 | + "<p>x</p>", |
| 265 | + "should support tags and expressions with text before (text)" |
| 266 | + ); |
| 267 | + |
| 268 | + assert_eq!( |
| 269 | + to_html_with_options("<em>x{1}</em>", &swc)?, |
| 270 | + "<p>x</p>", |
| 271 | + "should support tags and expressions with text between, early (text)" |
| 272 | + ); |
| 273 | + |
| 274 | + assert_eq!( |
| 275 | + to_html_with_options("<em>{1}x</em>", &swc)?, |
| 276 | + "<p>x</p>", |
| 277 | + "should support tags and expressions with text between, late (text)" |
| 278 | + ); |
| 279 | + |
| 280 | + assert_eq!( |
| 281 | + to_html_with_options("<em>{1}</em>x", &swc)?, |
| 282 | + "<p>x</p>", |
| 283 | + "should support tags and expressions with text after (text)" |
| 284 | + ); |
| 285 | + |
| 286 | + assert_eq!( |
| 287 | + to_html_with_options("<x/>{1}", &swc)?, |
| 288 | + "", |
| 289 | + "should support a tag and then an expression (flow)" |
| 290 | + ); |
| 291 | + |
| 292 | + assert_eq!( |
| 293 | + to_html_with_options("<x/>{1}x", &swc)?, |
| 294 | + "<p>x</p>", |
| 295 | + "should support a tag, an expression, then text (text)" |
| 296 | + ); |
| 297 | + |
| 298 | + assert_eq!( |
| 299 | + to_html_with_options("x<x/>{1}", &swc)?, |
| 300 | + "<p>x</p>", |
| 301 | + "should support text, a tag, then an expression (text)" |
| 302 | + ); |
| 303 | + |
| 304 | + assert_eq!( |
| 305 | + to_html_with_options("{1}<x/>", &swc)?, |
| 306 | + "", |
| 307 | + "should support an expression and then a tag (flow)" |
| 308 | + ); |
| 309 | + |
| 310 | + assert_eq!( |
| 311 | + to_html_with_options("{1}<x/>x", &swc)?, |
| 312 | + "<p>x</p>", |
| 313 | + "should support an expression, a tag, then text (text)" |
| 314 | + ); |
| 315 | + |
| 316 | + assert_eq!( |
| 317 | + to_html_with_options("x{1}<x/>", &swc)?, |
| 318 | + "<p>x</p>", |
| 319 | + "should support text, an expression, then a tag (text)" |
| 320 | + ); |
| 321 | + |
| 322 | + assert_eq!( |
| 323 | + to_html_with_options("<x>{[\n'',\n{c:''}\n]}</x>", &swc)?, |
| 324 | + "", |
| 325 | + "should nicely interleaf (micromark/micromark-extension-mdx-jsx#9)" |
| 326 | + ); |
| 327 | + |
| 328 | + assert_eq!( |
| 329 | + to_html_with_options( |
| 330 | + " |
| 331 | +<style>{` |
| 332 | + .foo {} |
| 333 | + .bar {} |
| 334 | +`}</style> |
| 335 | + ", |
| 336 | + &swc |
| 337 | + )?, |
| 338 | + "", |
| 339 | + "should nicely interleaf (mdx-js/mdx#1945)" |
| 340 | + ); |
| 341 | + |
| 342 | + Ok(()) |
| 343 | +} |
0 commit comments