From be0750878bcbedbd90587d341ccc26197045330c Mon Sep 17 00:00:00 2001 From: Adam Israel Date: Sun, 6 Jul 2025 20:45:11 -0400 Subject: [PATCH] Add thousands crate; better formatting of word count --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + src/main.rs | 5 +++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 91be7f8..09540a7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -867,6 +867,7 @@ dependencies = [ "serde_json", "shellexpand", "thiserror 2.0.12", + "thousands", "words-count", "yaml-front-matter", ] @@ -1571,6 +1572,12 @@ dependencies = [ "syn", ] +[[package]] +name = "thousands" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3bf63baf9f5039dadc247375c29eb13706706cfde997d0330d05aa63a77d8820" + [[package]] name = "tiff" version = "0.9.1" diff --git a/Cargo.toml b/Cargo.toml index 2c9faf0..e690b5f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,3 +26,4 @@ obsidian-rs = { git = "https://github.com/adamisrael/obsidian-rs.git" } # obsidian-rs = { path = "../obsidian-rs" } rand = "0.9.1" thiserror = "2.0.12" +thousands = "0.2.0" diff --git a/src/main.rs b/src/main.rs index da13ad1..d08c600 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ use md2ms::constants; use clap::Parser; +use thousands::Separable; use yaml_front_matter::Document; use std::path::PathBuf; @@ -168,7 +169,7 @@ fn compile(ctx: &mut Context) -> Result<(), Md2msError> { // If the author wants the word count, give them the exact count, not the approximate value. if ctx.word_count { - println!("Exact word count: {}", wc.words); + println!("Exact word count: {}", wc.words.separate_with_commas()); return Ok(()); } @@ -300,7 +301,7 @@ fn compile(ctx: &mut Context) -> Result<(), Md2msError> { Paragraph::new() .add_run( Run::new() - .add_text(format!("about {nwc} words")) + .add_text(format!("about {} words", nwc.separate_with_commas())) .size(constants::FONT_SIZE), ) .align(AlignmentType::Right),