From f1e3add2929b747245c567f1474ccdf5e7fe112e Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Thu, 5 Feb 2026 23:48:08 -0700 Subject: [PATCH] chore: add .rustfmt.toml --- .rustfmt.toml | 21 +++++++++++++++ src/content.rs | 6 ++--- src/error.rs | 14 +++++----- src/highlight.rs | 4 +-- src/main.rs | 18 ++++++------- src/math.rs | 2 +- src/render.rs | 58 +++++++++++++++++++++--------------------- src/template_engine.rs | 2 +- 8 files changed, 73 insertions(+), 52 deletions(-) create mode 100644 .rustfmt.toml diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 0000000..2192d67 --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1,21 @@ +edition = "2024" +newline_style = "unix" +use_field_init_shorthand = true +use_try_shorthand = true + +unstable_features = true + +comment_width = 100 +condense_wildcard_suffixes = true +error_on_line_overflow = true +format_code_in_doc_comments = true +format_macro_bodies = true +format_macro_matchers = true +format_strings = true +group_imports = "StdExternalCrate" +imports_granularity = "Module" +match_block_trailing_comma = true +normalize_doc_attributes = true +reorder_impl_items = true +style_edition = "2024" +wrap_comments = true diff --git a/src/content.rs b/src/content.rs index dfc47e2..b7af579 100644 --- a/src/content.rs +++ b/src/content.rs @@ -1,7 +1,7 @@ //! Content discovery and frontmatter parsing. use crate::error::{Error, Result}; -use gray_matter::{engine::YAML, Matter}; +use gray_matter::{Matter, engine::YAML}; use serde::Serialize; use std::fs; use std::path::{Path, PathBuf}; @@ -116,12 +116,12 @@ impl Content { // _index.md → parent/index.html (listing pages stay as index.html) let parent = relative.parent().unwrap_or(Path::new("")); parent.join("index.html") - } + }, _ => { // Regular content → parent/slug.html (flat structure) let parent = relative.parent().unwrap_or(Path::new("")); parent.join(format!("{}.html", self.slug)) - } + }, } } } diff --git a/src/error.rs b/src/error.rs index 2d9e7de..ecd9302 100644 --- a/src/error.rs +++ b/src/error.rs @@ -52,13 +52,13 @@ impl fmt::Display for Error { match self { Error::ReadFile { path, source } => { write!(f, "failed to read {}: {}", path.display(), source) - } + }, Error::Frontmatter { path, message } => { write!(f, "invalid frontmatter in {}: {}", path.display(), message) - } + }, Error::WriteFile { path, source } => { write!(f, "failed to write {}: {}", path.display(), source) - } + }, Error::CreateDir { path, source } => { write!( f, @@ -66,17 +66,17 @@ impl fmt::Display for Error { path.display(), source ) - } + }, Error::ContentDirNotFound(path) => { write!(f, "content directory not found: {}", path.display()) - } + }, Error::Config { path, message } => { write!(f, "invalid config in {}: {}", path.display(), message) - } + }, Error::TemplateLoad(e) => write!(f, "failed to load templates: {}", e), Error::TemplateRender { template, .. } => { write!(f, "failed to render template '{}'", template) - } + }, Error::CssBundle(msg) => write!(f, "CSS bundle error: {}", msg), } } diff --git a/src/highlight.rs b/src/highlight.rs index f6fc5c1..f928cc3 100644 --- a/src/highlight.rs +++ b/src/highlight.rs @@ -541,7 +541,7 @@ impl LanguageLoader for SukrLoader { InjectionLanguageMarker::Match(text) => text.into(), InjectionLanguageMarker::Filename(_) | InjectionLanguageMarker::Shebang(_) => { return None; - } + }, }; self.name_to_lang .get(name.to_lowercase().as_str()) @@ -618,7 +618,7 @@ fn render_html<'a>(source: &str, mut highlighter: Highlighter<'a, 'a, SukrLoader html.push_str(class); html.push_str("\">"); } - } + }, } } diff --git a/src/main.rs b/src/main.rs index 0a1474a..d049c97 100644 --- a/src/main.rs +++ b/src/main.rs @@ -45,12 +45,12 @@ fn main() { } std::process::exit(1); } - } - Ok(None) => {} // --help was printed + }, + Ok(None) => {}, // --help was printed Err(e) => { eprintln!("error: {e}"); std::process::exit(1); - } + }, } } @@ -65,17 +65,17 @@ fn parse_args() -> std::result::Result, String> { "-h" | "--help" => { print!("{USAGE}"); return Ok(None); - } + }, "-c" | "--config" => { if i + 1 >= args.len() { return Err("--config requires an argument".to_string()); } config_path = PathBuf::from(&args[i + 1]); i += 2; - } + }, arg => { return Err(format!("unknown argument: {arg}")); - } + }, } } @@ -118,7 +118,7 @@ fn run(config_path: &Path) -> Result<()> { "blog" => { // Blog: sort by date, newest first items.sort_by(|a, b| b.frontmatter.date.cmp(&a.frontmatter.date)); - } + }, "projects" => { // Projects: sort by weight items.sort_by(|a, b| { @@ -127,7 +127,7 @@ fn run(config_path: &Path) -> Result<()> { .unwrap_or(DEFAULT_WEIGHT_HIGH) .cmp(&b.frontmatter.weight.unwrap_or(DEFAULT_WEIGHT_HIGH)) }); - } + }, _ => { // Default: sort by weight then title items.sort_by(|a, b| { @@ -137,7 +137,7 @@ fn run(config_path: &Path) -> Result<()> { .cmp(&b.frontmatter.weight.unwrap_or(DEFAULT_WEIGHT)) .then_with(|| a.frontmatter.title.cmp(&b.frontmatter.title)) }); - } + }, } // Render individual content pages for all sections diff --git a/src/math.rs b/src/math.rs index 5682249..6205e62 100644 --- a/src/math.rs +++ b/src/math.rs @@ -2,7 +2,7 @@ //! //! Converts LaTeX math expressions to HTML at build-time. -use katex::{render_to_string, KatexContext, Settings}; +use katex::{KatexContext, Settings, render_to_string}; /// Render a LaTeX math expression to HTML. /// diff --git a/src/render.rs b/src/render.rs index 947e686..be62722 100644 --- a/src/render.rs +++ b/src/render.rs @@ -1,7 +1,7 @@ //! Markdown to HTML rendering via pulldown-cmark with syntax highlighting. use crate::escape::{code_escape, html_escape}; -use crate::highlight::{highlight_code, Language}; +use crate::highlight::{Language, highlight_code}; use pulldown_cmark::{CodeBlockKind, Event, HeadingLevel, Options, Parser, Tag, TagEnd}; use serde::Serialize; @@ -52,22 +52,22 @@ pub fn markdown_to_html(markdown: &str) -> (String, Vec) { } else { Some(lang_str.to_string()) } - } + }, CodeBlockKind::Indented => None, }; in_code_block = true; code_block_content.clear(); - } + }, Event::Text(text) if in_code_block => { // Accumulate code block content code_block_content.push_str(&text); - } + }, Event::Text(text) if image_alt_content.is_some() => { // Accumulate image alt text if let Some(ref mut alt) = image_alt_content { alt.push_str(&text); } - } + }, Event::End(TagEnd::CodeBlock) => { // Render the code block with highlighting let lang_str = code_block_lang.as_deref().unwrap_or(""); @@ -79,13 +79,13 @@ pub fn markdown_to_html(markdown: &str) -> (String, Vec) { html_output.push_str("
\n"); html_output.push_str(&svg); html_output.push_str("\n
\n"); - } + }, Err(e) => { eprintln!("mermaid render error: {e}"); html_output.push_str("
");
                             html_output.push_str(&html_escape(&code_block_content));
                             html_output.push_str("
\n"); - } + }, } } else { // Code blocks: syntax highlighting @@ -111,29 +111,29 @@ pub fn markdown_to_html(markdown: &str) -> (String, Vec) { code_block_lang = None; in_code_block = false; code_block_content.clear(); - } + }, Event::Text(text) if heading_level.is_some() => { // Accumulate heading text heading_text.push_str(&text); html_output.push_str(&html_escape(&text)); - } + }, Event::Text(text) => { // Regular text outside code blocks html_output.push_str(&html_escape(&text)); - } + }, Event::Code(text) => { // Inline code html_output.push_str(""); html_output.push_str(&html_escape(&text)); html_output.push_str(""); - } + }, Event::Start(Tag::Image { dest_url, title, .. }) => { // Begin accumulating alt text; defer rendering to End event image_alt_content = Some(String::new()); image_attrs = Some((dest_url.to_string(), title.to_string())); - } + }, Event::Start(Tag::Heading { level, .. }) => { // Begin accumulating heading text heading_level = Some(level); @@ -141,10 +141,10 @@ pub fn markdown_to_html(markdown: &str) -> (String, Vec) { let level_num = level as u8; html_output.push_str(&format!(" { html_output.push_str(&start_tag_to_html(&tag)); - } + }, Event::End(TagEnd::Image) => { // Render image with accumulated alt text let alt = image_alt_content.take().unwrap_or_default(); @@ -164,7 +164,7 @@ pub fn markdown_to_html(markdown: &str) -> (String, Vec) { )); } } - } + }, Event::End(TagEnd::Heading(level)) => { // Generate slug ID from heading text let id = slugify(&heading_text); @@ -193,28 +193,28 @@ pub fn markdown_to_html(markdown: &str) -> (String, Vec) { heading_level = None; heading_text.clear(); - } + }, Event::End(tag) => { html_output.push_str(&end_tag_to_html(&tag)); - } + }, Event::SoftBreak => { html_output.push('\n'); - } + }, Event::HardBreak => { html_output.push_str("
\n"); - } + }, Event::Rule => { html_output.push_str("
\n"); - } + }, Event::Html(html) | Event::InlineHtml(html) => { html_output.push_str(&html); - } + }, Event::FootnoteReference(name) => { html_output.push_str(&format!( "{}", name, name )); - } + }, Event::TaskListMarker(checked) => { let checkbox = if checked { "" @@ -222,7 +222,7 @@ pub fn markdown_to_html(markdown: &str) -> (String, Vec) { "" }; html_output.push_str(checkbox); - } + }, Event::InlineMath(latex) => match crate::math::render_math(&latex, false) { Ok(rendered) => html_output.push_str(&rendered), Err(e) => { @@ -230,20 +230,20 @@ pub fn markdown_to_html(markdown: &str) -> (String, Vec) { html_output.push_str(""); html_output.push_str(&html_escape(&latex)); html_output.push_str(""); - } + }, }, Event::DisplayMath(latex) => match crate::math::render_math(&latex, true) { Ok(rendered) => { html_output.push_str("
\n"); html_output.push_str(&rendered); html_output.push_str("\n
\n"); - } + }, Err(e) => { eprintln!("math render error: {e}"); html_output.push_str("
");
                     html_output.push_str(&html_escape(&latex));
                     html_output.push_str("
\n"); - } + }, }, } } @@ -274,7 +274,7 @@ fn start_tag_to_html(tag: &Tag) -> String { Tag::Item => "
  • ".to_string(), Tag::FootnoteDefinition(name) => { format!("
    ", name) - } + }, Tag::Table(_) => "\n".to_string(), Tag::TableHead => "\n\n".to_string(), Tag::TableRow => "\n".to_string(), @@ -294,7 +294,7 @@ fn start_tag_to_html(tag: &Tag) -> String { html_escape(title) ) } - } + }, Tag::Image { .. } => String::new(), // Handled separately in main loop Tag::HtmlBlock => String::new(), Tag::MetadataBlock(_) => String::new(), @@ -316,7 +316,7 @@ fn end_tag_to_html(tag: &TagEnd) -> String { } else { "\n".to_string() } - } + }, TagEnd::Item => "\n".to_string(), TagEnd::FootnoteDefinition => "\n".to_string(), TagEnd::Table => "
    \n".to_string(), diff --git a/src/template_engine.rs b/src/template_engine.rs index 03fd020..1524f7b 100644 --- a/src/template_engine.rs +++ b/src/template_engine.rs @@ -215,7 +215,7 @@ fn strip_parens_filter(value: &Value, _args: &HashMap) -> tera::R s.clone() }; Ok(Value::String(result)) - } + }, _ => Ok(value.clone()), } }