diff --git a/src/plugins/syntect.rs b/src/plugins/syntect.rs index 70ab13ab..5a8ea426 100644 --- a/src/plugins/syntect.rs +++ b/src/plugins/syntect.rs @@ -58,7 +58,7 @@ impl SyntaxHighlighterAdapter for SyntectAdapter { let fallback_syntax = "Plain Text"; let lang: &str = match lang { - Some(l) if !l.is_empty() => l, + Some(l) if !l.is_empty() => l.split_once(',').map(|(left, _)| left).unwrap_or(l), _ => fallback_syntax, }; diff --git a/src/tests/plugins.rs b/src/tests/plugins.rs index 0aa3d659..2797df9b 100644 --- a/src/tests/plugins.rs +++ b/src/tests/plugins.rs @@ -91,16 +91,37 @@ fn heading_adapter_plugin() { fn syntect_plugin() { let adapter = crate::plugins::syntect::SyntectAdapter::new("base16-ocean.dark"); - let input = concat!("```rust\n", "fn main<'a>();\n", "```\n"); - let expected = concat!( - "
",
- "fn main",
- "<'a>();\n",
- "
\n"
- );
+ let cases = vec![
+ (
+ concat!("```rust\n", "fn main<'a>();\n", "```\n"),
+ concat!(
+ "",
+ "fn main",
+ "<'a>();\n",
+ "
\n"
+ ),
+ ),
+ (
+ // Language should still be highlighted when delimited by a comma
+ "\
+ ```rust,ignore\n\
+ fn main() {}\n\
+ ```\n\
+ ",
+ "\
+ \
+ fn \
+ main\
+ () {}\n\
+
\n\
+ ",
+ ),
+ ];
let mut plugins = Plugins::default();
plugins.render.codefence_syntax_highlighter = Some(&adapter);
- html_plugins(input, expected, &plugins);
+ for (input, expected) in cases {
+ html_plugins(input, expected, &plugins);
+ }
}