Skip to content

Commit 2bd7630

Browse files
author
tjk
committed
Add test for with_custom_sets on SyntectWriter
1 parent 8ef9166 commit 2bd7630

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

lib/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub use html::{
7474
create_html_renderer, push_html, push_html_with_highlighting, write_html_fmt, write_html_io,
7575
AttributeMappings, CodeBlockOptions, DefaultHtmlWriter, ElementOptions, HeadingOptions,
7676
HtmlConfig, HtmlError, HtmlOptions, HtmlRenderer, HtmlState, HtmlWriter, LinkOptions,
77-
SyntectConfig, SyntectConfigStyle,
77+
SyntectConfig, SyntectConfigStyle, SyntectWriter,
7878
};
7979

8080
#[cfg(test)]

lib/tests/syntect.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
#[cfg(test)]
22
mod tests {
3+
use pulldown_cmark_escape::FmtWriter;
4+
use pulldown_html_ext::HtmlWriter;
5+
use pulldown_html_ext::SyntectWriter;
36
use pulldown_html_ext::{
47
push_html_with_highlighting, HtmlConfig, SyntectConfig, SyntectConfigStyle,
58
};
69
use syntect::highlighting::ThemeSet;
10+
711
use syntect::html::ClassStyle;
812
use syntect::parsing::SyntaxSet;
913

@@ -34,6 +38,34 @@ mod tests {
3438
assert!(html.contains("language-rust"));
3539
}
3640

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+
}
3769
#[test]
3870
fn test_custom_syntax_set() {
3971
let syntax_set = SyntaxSet::new();

0 commit comments

Comments
 (0)