|
1 | 1 | #[cfg(test)] |
2 | 2 | mod tests { |
| 3 | + use pulldown_cmark_escape::FmtWriter; |
| 4 | + use pulldown_html_ext::HtmlWriter; |
| 5 | + use pulldown_html_ext::SyntectWriter; |
3 | 6 | use pulldown_html_ext::{ |
4 | 7 | push_html_with_highlighting, HtmlConfig, SyntectConfig, SyntectConfigStyle, |
5 | 8 | }; |
6 | 9 | use syntect::highlighting::ThemeSet; |
| 10 | + |
7 | 11 | use syntect::html::ClassStyle; |
8 | 12 | use syntect::parsing::SyntaxSet; |
9 | 13 |
|
@@ -34,6 +38,34 @@ mod tests { |
34 | 38 | assert!(html.contains("language-rust")); |
35 | 39 | } |
36 | 40 |
|
| 41 | + #[test] |
| 42 | + fn test_custom_syntax_sets() { |
| 43 | + let mut output = String::new(); |
| 44 | + let config = HtmlConfig::default(); |
| 45 | + let syntax_set = SyntaxSet::load_defaults_newlines(); |
| 46 | + let theme_set = ThemeSet::load_defaults(); |
| 47 | + |
| 48 | + let mut writer = SyntectWriter::with_custom_sets( |
| 49 | + FmtWriter(&mut output), |
| 50 | + &config, |
| 51 | + Some(&syntax_set), |
| 52 | + Some(&theme_set), |
| 53 | + ); |
| 54 | + |
| 55 | + // Test with a specific language that's in the custom syntax set |
| 56 | + writer |
| 57 | + .start_code_block(pulldown_cmark::CodeBlockKind::Fenced("rust".into())) |
| 58 | + .unwrap(); |
| 59 | + writer |
| 60 | + .text("fn main() {\n println!(\"Hello, world!\");\n}") |
| 61 | + .unwrap(); |
| 62 | + writer.end_code_block().unwrap(); |
| 63 | + |
| 64 | + // Verify output contains syntax highlighted code |
| 65 | + assert!(output.contains("class=\"")); // Should have syntax highlighting classes |
| 66 | + assert!(output.contains("fn")); // Should contain the code |
| 67 | + assert!(output.contains("println")); // Should contain the code |
| 68 | + } |
37 | 69 | #[test] |
38 | 70 | fn test_custom_syntax_set() { |
39 | 71 | let syntax_set = SyntaxSet::new(); |
|
0 commit comments