use comrak::ComrakOptions; use mdx_gen::{process_markdown, MarkdownOptions}; #[test] fn test_complex_markdown_with_all_features() { let markdown = r#" # Advanced Markdown Processing Test ## Custom Blocks
"#));
assert!(html.contains("Hello, world!"));
assert!(html.contains(
r#""#
));
assert!(
html.contains(r#"A "#)
);
assert!(html
.contains(r#"B "#));
assert!(
html.contains(r#"C "#)
);
assert!(html.contains("bold"));
assert!(html.contains("italic"));
assert!(html.contains(""));
assert!(html.contains(""));
assert!(html.contains(r#"Link to Rust website"#));
assert!(html.contains(""));
assert!(html.contains("
Header 1"));
assert!(html.contains("Header 2
"));
assert!(html.contains("Header 3
"));
assert!(html.contains("This is a simple paragraph with bold text and italic text.
"));
assert!(html.contains("
Another paragraph."));
}
#[test]
fn test_links_and_images() {
let markdown = r#"
[Link to Rust](https://www.rust-lang.org/)
![Rust logo](https://www.rust-lang.org/static/images/rust-logo-blk.svg)
"#;
let options = MarkdownOptions::new()
.with_custom_blocks(true)
.with_syntax_highlighting(true)
.with_enhanced_tables(true)
.with_comrak_options({
let mut opts = ComrakOptions::default();
opts.extension.table = true;
opts.extension.strikethrough = true;
opts.extension.tasklist = true;
opts.extension.autolink = true;
opts
});
let result = process_markdown(markdown, &options);
assert!(
result.is_ok(),
"Markdown processing failed: {:?}",
result.err()
);
let html = result.unwrap();
// Check for links and images
assert!(html.contains(
r#"Link to Rust"#
));
assert!(html.contains(r#""#));
}
#[test]
fn test_lists_and_blockquotes() {
let markdown = r#"
1. First ordered item
2. Second ordered item
- Subitem 1
- Subitem 2
> This is a blockquote.
"#;
let options = MarkdownOptions::new()
.with_custom_blocks(true)
.with_syntax_highlighting(true)
.with_enhanced_tables(true)
.with_comrak_options({
let mut opts = ComrakOptions::default();
opts.extension.table = true;
opts.extension.strikethrough = true;
opts.extension.tasklist = true;
opts.extension.autolink = true;
opts
});
let result = process_markdown(markdown, &options);
assert!(
result.is_ok(),
"Markdown processing failed: {:?}",
result.err()
);
let html = result.unwrap();
// Check for lists and blockquotes
assert!(html.contains(""));
assert!(html.contains(""));
assert!(html.contains(""));
}
#[test]
fn test_horizontal_rules_and_inline_code() {
let markdown = r#"
This is some inline `code`.
---
Another line followed by an HR.
"#;
let options = MarkdownOptions::new()
.with_custom_blocks(true)
.with_syntax_highlighting(true)
.with_enhanced_tables(true)
.with_comrak_options({
let mut opts = ComrakOptions::default();
opts.extension.table = true;
opts.extension.strikethrough = true;
opts.extension.tasklist = true;
opts.extension.autolink = true;
opts
});
let result = process_markdown(markdown, &options);
assert!(
result.is_ok(),
"Markdown processing failed: {:?}",
result.err()
);
let html = result.unwrap();
// Check for inline code and horizontal rule
assert!(html.contains("code
"));
assert!(html.contains("
Strikethrough text"));
// Check for task list with correct HTML structure
assert!(html.contains(r#"- Task 1
"#),
"Task list rendering failed. Actual HTML: {}", html);
assert!(
html.contains(
r#"- Task 2
"#
),
"Task list rendering failed. Actual HTML: {}",
html
);
}
#[test]
fn test_autolink_urls() {
let markdown = r#"
Here is a URL: https://www.example.com
"#;
let options = MarkdownOptions::new()
.with_custom_blocks(true)
.with_syntax_highlighting(true)
.with_enhanced_tables(true)
.with_comrak_options({
let mut opts = ComrakOptions::default();
opts.extension.table = true;
opts.extension.strikethrough = true;
opts.extension.tasklist = true;
opts.extension.autolink = true;
opts
});
let result = process_markdown(markdown, &options);
assert!(
result.is_ok(),
"Markdown processing failed: {:?}",
result.err()
);
let html = result.unwrap();
// Check for autolinked URL
assert!(html.contains(r#"https://www.example.com"#));
}
#[test]
fn test_nested_blockquotes() {
let markdown = r#"
> This is a blockquote.
>
> > This is a nested blockquote.
"#;
let options = MarkdownOptions::new()
.with_custom_blocks(true)
.with_syntax_highlighting(true)
.with_enhanced_tables(true)
.with_comrak_options({
let mut opts = ComrakOptions::default();
opts.extension.table = true;
opts.extension.strikethrough = true;
opts.extension.tasklist = true;
opts.extension.autolink = true;
opts
});
let result = process_markdown(markdown, &options);
assert!(
result.is_ok(),
"Markdown processing failed: {:?}",
result.err()
);
let html = result.unwrap();
// Check for nested blockquotes
assert!(html.contains("\nThis is a blockquote.
\n\nThis is a nested blockquote.
\n
\n
"));
}
#[test]
fn test_emphasis_in_block_elements() {
let markdown = r#"
> **Bold text** and *italic text* inside a blockquote.
"#;
let options = MarkdownOptions::new()
.with_custom_blocks(true)
.with_syntax_highlighting(true)
.with_enhanced_tables(true)
.with_comrak_options({
let mut opts = ComrakOptions::default();
opts.extension.table = true;
opts.extension.strikethrough = true;
opts.extension.tasklist = true;
opts.extension.autolink = true;
opts
});
let result = process_markdown(markdown, &options);
assert!(
result.is_ok(),
"Markdown processing failed: {:?}",
result.err()
);
let html = result.unwrap();
// Check for bold and italic inside blockquote
assert!(html.contains("\nBold text and italic text inside a blockquote.
\n
"));
}