chore: address clippy lints
This commit is contained in:
@@ -778,8 +778,8 @@ mod tests {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Create blog posts with dates
|
// Create blog posts with dates
|
||||||
let post1 = format!("---\ntitle: \"Post 1\"\ndate: \"2026-01-15\"\n---\nContent.");
|
let post1 = "---\ntitle: \"Post 1\"\ndate: \"2026-01-15\"\n---\nContent.".to_string();
|
||||||
let post2 = format!("---\ntitle: \"Post 2\"\ndate: \"2026-01-20\"\n---\nContent.");
|
let post2 = "---\ntitle: \"Post 2\"\ndate: \"2026-01-20\"\n---\nContent.".to_string();
|
||||||
fs::write(content_dir.join("blog/post1.md"), &post1).unwrap();
|
fs::write(content_dir.join("blog/post1.md"), &post1).unwrap();
|
||||||
fs::write(content_dir.join("blog/post2.md"), &post2).unwrap();
|
fs::write(content_dir.join("blog/post2.md"), &post2).unwrap();
|
||||||
|
|
||||||
|
|||||||
120
src/highlight.rs
120
src/highlight.rs
@@ -334,65 +334,65 @@ impl SukrLoader {
|
|||||||
|
|
||||||
// Create configs for each language
|
// Create configs for each language
|
||||||
// Each grammar is converted using TryFrom<LanguageFn> for Grammar
|
// Each grammar is converted using TryFrom<LanguageFn> for Grammar
|
||||||
if let Ok(grammar) = Grammar::try_from(tree_sitter_bash::LANGUAGE) {
|
if let Ok(grammar) = Grammar::try_from(tree_sitter_bash::LANGUAGE)
|
||||||
if let Some(config) = make_config(
|
&& let Some(config) = make_config(
|
||||||
grammar,
|
grammar,
|
||||||
include_str!("../queries/bash/highlights.scm"),
|
include_str!("../queries/bash/highlights.scm"),
|
||||||
include_str!("../queries/bash/injections.scm"),
|
include_str!("../queries/bash/injections.scm"),
|
||||||
"",
|
"",
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
config.configure(resolve_scope);
|
config.configure(resolve_scope);
|
||||||
configs.insert(Language::Bash, config);
|
configs.insert(Language::Bash, config);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if let Ok(grammar) = Grammar::try_from(tree_sitter_c::LANGUAGE) {
|
if let Ok(grammar) = Grammar::try_from(tree_sitter_c::LANGUAGE)
|
||||||
if let Some(config) = make_config(
|
&& let Some(config) = make_config(
|
||||||
grammar,
|
grammar,
|
||||||
include_str!("../queries/c/highlights.scm"),
|
include_str!("../queries/c/highlights.scm"),
|
||||||
include_str!("../queries/c/injections.scm"),
|
include_str!("../queries/c/injections.scm"),
|
||||||
include_str!("../queries/c/locals.scm"),
|
include_str!("../queries/c/locals.scm"),
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
config.configure(resolve_scope);
|
config.configure(resolve_scope);
|
||||||
configs.insert(Language::C, config);
|
configs.insert(Language::C, config);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if let Ok(grammar) = Grammar::try_from(tree_sitter_css::LANGUAGE) {
|
if let Ok(grammar) = Grammar::try_from(tree_sitter_css::LANGUAGE)
|
||||||
if let Some(config) = make_config(
|
&& let Some(config) = make_config(
|
||||||
grammar,
|
grammar,
|
||||||
include_str!("../queries/css/highlights.scm"),
|
include_str!("../queries/css/highlights.scm"),
|
||||||
include_str!("../queries/css/injections.scm"),
|
include_str!("../queries/css/injections.scm"),
|
||||||
"",
|
"",
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
config.configure(resolve_scope);
|
config.configure(resolve_scope);
|
||||||
configs.insert(Language::Css, config);
|
configs.insert(Language::Css, config);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if let Ok(grammar) = Grammar::try_from(tree_sitter_go::LANGUAGE) {
|
if let Ok(grammar) = Grammar::try_from(tree_sitter_go::LANGUAGE)
|
||||||
if let Some(config) = make_config(
|
&& let Some(config) = make_config(
|
||||||
grammar,
|
grammar,
|
||||||
include_str!("../queries/go/highlights.scm"),
|
include_str!("../queries/go/highlights.scm"),
|
||||||
include_str!("../queries/go/injections.scm"),
|
include_str!("../queries/go/injections.scm"),
|
||||||
include_str!("../queries/go/locals.scm"),
|
include_str!("../queries/go/locals.scm"),
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
config.configure(resolve_scope);
|
config.configure(resolve_scope);
|
||||||
configs.insert(Language::Go, config);
|
configs.insert(Language::Go, config);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if let Ok(grammar) = Grammar::try_from(tree_sitter_html::LANGUAGE) {
|
if let Ok(grammar) = Grammar::try_from(tree_sitter_html::LANGUAGE)
|
||||||
if let Some(config) = make_config(
|
&& let Some(config) = make_config(
|
||||||
grammar,
|
grammar,
|
||||||
include_str!("../queries/html/highlights.scm"),
|
include_str!("../queries/html/highlights.scm"),
|
||||||
include_str!("../queries/html/injections.scm"),
|
include_str!("../queries/html/injections.scm"),
|
||||||
"",
|
"",
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
config.configure(resolve_scope);
|
config.configure(resolve_scope);
|
||||||
configs.insert(Language::Html, config);
|
configs.insert(Language::Html, config);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// JavaScript needs combined queries from ecma + _javascript
|
// JavaScript needs combined queries from ecma + _javascript
|
||||||
let js_highlights = [
|
let js_highlights = [
|
||||||
@@ -406,89 +406,89 @@ impl SukrLoader {
|
|||||||
]
|
]
|
||||||
.join("\n");
|
.join("\n");
|
||||||
|
|
||||||
if let Ok(grammar) = Grammar::try_from(tree_sitter_javascript::LANGUAGE) {
|
if let Ok(grammar) = Grammar::try_from(tree_sitter_javascript::LANGUAGE)
|
||||||
if let Some(config) = make_config(
|
&& let Some(config) = make_config(
|
||||||
grammar,
|
grammar,
|
||||||
&js_highlights,
|
&js_highlights,
|
||||||
include_str!("../queries/ecma/injections.scm"),
|
include_str!("../queries/ecma/injections.scm"),
|
||||||
&js_locals,
|
&js_locals,
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
config.configure(resolve_scope);
|
config.configure(resolve_scope);
|
||||||
configs.insert(Language::JavaScript, config);
|
configs.insert(Language::JavaScript, config);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if let Ok(grammar) = Grammar::try_from(tree_sitter_json::LANGUAGE) {
|
if let Ok(grammar) = Grammar::try_from(tree_sitter_json::LANGUAGE)
|
||||||
if let Some(config) = make_config(
|
&& let Some(config) = make_config(
|
||||||
grammar,
|
grammar,
|
||||||
include_str!("../queries/json/highlights.scm"),
|
include_str!("../queries/json/highlights.scm"),
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
config.configure(resolve_scope);
|
config.configure(resolve_scope);
|
||||||
configs.insert(Language::Json, config);
|
configs.insert(Language::Json, config);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if let Ok(grammar) = Grammar::try_from(tree_sitter_md::LANGUAGE) {
|
if let Ok(grammar) = Grammar::try_from(tree_sitter_md::LANGUAGE)
|
||||||
if let Some(config) = make_config(
|
&& let Some(config) = make_config(
|
||||||
grammar,
|
grammar,
|
||||||
include_str!("../queries/markdown/highlights.scm"),
|
include_str!("../queries/markdown/highlights.scm"),
|
||||||
include_str!("../queries/markdown/injections.scm"),
|
include_str!("../queries/markdown/injections.scm"),
|
||||||
"",
|
"",
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
config.configure(resolve_scope);
|
config.configure(resolve_scope);
|
||||||
configs.insert(Language::Markdown, config);
|
configs.insert(Language::Markdown, config);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if let Ok(grammar) = Grammar::try_from(tree_sitter_nix::LANGUAGE) {
|
if let Ok(grammar) = Grammar::try_from(tree_sitter_nix::LANGUAGE)
|
||||||
if let Some(config) = make_config(
|
&& let Some(config) = make_config(
|
||||||
grammar,
|
grammar,
|
||||||
include_str!("../queries/nix/highlights.scm"),
|
include_str!("../queries/nix/highlights.scm"),
|
||||||
include_str!("../queries/nix/injections.scm"),
|
include_str!("../queries/nix/injections.scm"),
|
||||||
"",
|
"",
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
config.configure(resolve_scope);
|
config.configure(resolve_scope);
|
||||||
configs.insert(Language::Nix, config);
|
configs.insert(Language::Nix, config);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if let Ok(grammar) = Grammar::try_from(tree_sitter_python::LANGUAGE) {
|
if let Ok(grammar) = Grammar::try_from(tree_sitter_python::LANGUAGE)
|
||||||
if let Some(config) = make_config(
|
&& let Some(config) = make_config(
|
||||||
grammar,
|
grammar,
|
||||||
include_str!("../queries/python/highlights.scm"),
|
include_str!("../queries/python/highlights.scm"),
|
||||||
include_str!("../queries/python/injections.scm"),
|
include_str!("../queries/python/injections.scm"),
|
||||||
include_str!("../queries/python/locals.scm"),
|
include_str!("../queries/python/locals.scm"),
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
config.configure(resolve_scope);
|
config.configure(resolve_scope);
|
||||||
configs.insert(Language::Python, config);
|
configs.insert(Language::Python, config);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if let Ok(grammar) = Grammar::try_from(tree_sitter_rust::LANGUAGE) {
|
if let Ok(grammar) = Grammar::try_from(tree_sitter_rust::LANGUAGE)
|
||||||
if let Some(config) = make_config(
|
&& let Some(config) = make_config(
|
||||||
grammar,
|
grammar,
|
||||||
include_str!("../queries/rust/highlights.scm"),
|
include_str!("../queries/rust/highlights.scm"),
|
||||||
include_str!("../queries/rust/injections.scm"),
|
include_str!("../queries/rust/injections.scm"),
|
||||||
include_str!("../queries/rust/locals.scm"),
|
include_str!("../queries/rust/locals.scm"),
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
config.configure(resolve_scope);
|
config.configure(resolve_scope);
|
||||||
configs.insert(Language::Rust, config);
|
configs.insert(Language::Rust, config);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if let Ok(grammar) = Grammar::try_from(tree_sitter_toml_ng::LANGUAGE) {
|
if let Ok(grammar) = Grammar::try_from(tree_sitter_toml_ng::LANGUAGE)
|
||||||
if let Some(config) = make_config(
|
&& let Some(config) = make_config(
|
||||||
grammar,
|
grammar,
|
||||||
include_str!("../queries/toml/highlights.scm"),
|
include_str!("../queries/toml/highlights.scm"),
|
||||||
include_str!("../queries/toml/injections.scm"),
|
include_str!("../queries/toml/injections.scm"),
|
||||||
"",
|
"",
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
config.configure(resolve_scope);
|
config.configure(resolve_scope);
|
||||||
configs.insert(Language::Toml, config);
|
configs.insert(Language::Toml, config);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// TypeScript needs combined queries from ecma + _typescript
|
// TypeScript needs combined queries from ecma + _typescript
|
||||||
let ts_highlights = [
|
let ts_highlights = [
|
||||||
@@ -502,29 +502,29 @@ impl SukrLoader {
|
|||||||
]
|
]
|
||||||
.join("\n");
|
.join("\n");
|
||||||
|
|
||||||
if let Ok(grammar) = Grammar::try_from(tree_sitter_typescript::LANGUAGE_TYPESCRIPT) {
|
if let Ok(grammar) = Grammar::try_from(tree_sitter_typescript::LANGUAGE_TYPESCRIPT)
|
||||||
if let Some(config) = make_config(
|
&& let Some(config) = make_config(
|
||||||
grammar,
|
grammar,
|
||||||
&ts_highlights,
|
&ts_highlights,
|
||||||
include_str!("../queries/ecma/injections.scm"),
|
include_str!("../queries/ecma/injections.scm"),
|
||||||
&ts_locals,
|
&ts_locals,
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
config.configure(resolve_scope);
|
config.configure(resolve_scope);
|
||||||
configs.insert(Language::TypeScript, config);
|
configs.insert(Language::TypeScript, config);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if let Ok(grammar) = Grammar::try_from(tree_sitter_yaml::LANGUAGE) {
|
if let Ok(grammar) = Grammar::try_from(tree_sitter_yaml::LANGUAGE)
|
||||||
if let Some(config) = make_config(
|
&& let Some(config) = make_config(
|
||||||
grammar,
|
grammar,
|
||||||
include_str!("../queries/yaml/highlights.scm"),
|
include_str!("../queries/yaml/highlights.scm"),
|
||||||
include_str!("../queries/yaml/injections.scm"),
|
include_str!("../queries/yaml/injections.scm"),
|
||||||
"",
|
"",
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
config.configure(resolve_scope);
|
config.configure(resolve_scope);
|
||||||
configs.insert(Language::Yaml, config);
|
configs.insert(Language::Yaml, config);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
configs,
|
configs,
|
||||||
@@ -563,7 +563,7 @@ pub fn highlight_code(lang: Language, source: &str) -> String {
|
|||||||
let loader = &*LOADER;
|
let loader = &*LOADER;
|
||||||
|
|
||||||
// Check if we have a config for this language
|
// Check if we have a config for this language
|
||||||
if loader.configs.get(&lang).is_none() {
|
if !loader.configs.contains_key(&lang) {
|
||||||
return html_escape(source);
|
return html_escape(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -609,8 +609,9 @@ fn render_html<'a>(source: &str, mut highlighter: Highlighter<'a, 'a, SukrLoader
|
|||||||
match event {
|
match event {
|
||||||
HighlightEvent::Refresh | HighlightEvent::Push => {
|
HighlightEvent::Refresh | HighlightEvent::Push => {
|
||||||
// Open spans for active highlights (use the most specific one)
|
// Open spans for active highlights (use the most specific one)
|
||||||
if highlights.len() > 0 {
|
if highlights.len() > 0
|
||||||
if let Some(highlight) = highlights.into_iter().last() {
|
&& let Some(highlight) = highlights.into_iter().next_back()
|
||||||
|
{
|
||||||
let class = scope_to_class(highlight);
|
let class = scope_to_class(highlight);
|
||||||
html.push_str("<span class=\"");
|
html.push_str("<span class=\"");
|
||||||
html.push_str(class);
|
html.push_str(class);
|
||||||
@@ -619,7 +620,6 @@ fn render_html<'a>(source: &str, mut highlighter: Highlighter<'a, 'a, SukrLoader
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
html
|
html
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user