Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comma delimited info string language #328

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/plugins/syntect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down
37 changes: 29 additions & 8 deletions src/tests/plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
"<pre style=\"background-color:#2b303b;\"><code class=\"language-rust\">",
"<span style=\"color:#b48ead;\">fn </span><span style=\"color:#8fa1b3;\">main</span><span style=\"color:#c0c5ce;\">",
"&lt;</span><span style=\"color:#b48ead;\">&#39;a</span><span style=\"color:#c0c5ce;\">&gt;();\n</span>",
"</code></pre>\n"
);
let cases = vec![
(
concat!("```rust\n", "fn main<'a>();\n", "```\n"),
concat!(
"<pre style=\"background-color:#2b303b;\"><code class=\"language-rust\">",
"<span style=\"color:#b48ead;\">fn </span><span style=\"color:#8fa1b3;\">main</span><span style=\"color:#c0c5ce;\">",
"&lt;</span><span style=\"color:#b48ead;\">&#39;a</span><span style=\"color:#c0c5ce;\">&gt;();\n</span>",
"</code></pre>\n"
),
),
(
// Language should still be highlighted when delimited by a comma
"\
```rust,ignore\n\
fn main() {}\n\
```\n\
",
"\
<pre style=\"background-color:#2b303b;\"><code class=\"language-rust,ignore\">\
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still has class="language-rust,ignore", so it wouldn't match anything looking for the class language-rust.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see now that this doesn't fit your use case. Changing that would differ from cmark-gfm's output, but I should be able to add that functionality behind a parse option instead

I'll work on handling that today

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does match GitHub's behavior though, so maybe cmark-gfm has a bug 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My guess is that GitHub uses the full-info-string option (which gives the full info string, not just the first word) and then parses the language out themselves. That's what we do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure on how to proceed, so I'll just be awaiting more definitive feedback

<span style=\"color:#b48ead;\">fn </span>\
<span style=\"color:#8fa1b3;\">main</span>\
<span style=\"color:#c0c5ce;\">() {}\n</span>\
</code></pre>\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);
}
}