From 8586d9e98ca82c05d882ab7ba24d039b15683e70 Mon Sep 17 00:00:00 2001 From: DerDrodt Date: Sun, 9 Nov 2025 14:05:36 +0100 Subject: [PATCH 1/2] Handle comma-suffix in names --- Cargo.toml | 6 ++---- src/csl/rendering/names.rs | 4 ++++ src/csl/taxonomy.rs | 7 +++++++ src/interop.rs | 1 + src/types/persons.rs | 11 ++++++++++- tests/citeproc-pass.txt | 1 + 6 files changed, 25 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7ee86d26..f24a95e2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ archive = ["ciborium"] csl-json = ["citationberg/json"] [dependencies] -citationberg = "0.6.1" +citationberg = { git = "https://github.com/DerDrodt/Citationberg.git", branch = "comma-suffix" } indexmap = { version = "2.0.2", features = ["serde"] } roman-numerals-rs = "3.1.0" paste = "1.0.14" @@ -28,9 +28,7 @@ unic-langid = { version = "0.9.6", features = ["serde"] } unicode-segmentation = "1.6.0" unscanny = "0.1.0" url = { version = "2.4", features = ["serde"] } -biblatex = { version = "0.11.0", features = [ - "unic-langid", -], optional = true } +biblatex = { version = "0.11.0", features = ["unic-langid"], optional = true } ciborium = { version = "0.2.1", optional = true } clap = { version = "4", optional = true, features = ["cargo"] } strum = { version = "0.26", features = ["derive"], optional = true } diff --git a/src/csl/rendering/names.rs b/src/csl/rendering/names.rs index 977dc92a..ec1e799e 100644 --- a/src/csl/rendering/names.rs +++ b/src/csl/rendering/names.rs @@ -599,6 +599,7 @@ fn write_name( family_part.map(|p| &p.affixes).and_then(|f| f.prefix.as_ref()), family_part.map(|p| &p.affixes).and_then(|f| f.suffix.as_ref()), ]; + let comma_suffix = name.comma_suffix; let first_name = |ctx: &mut Context| { if let Some(first) = &name.given_name { @@ -809,6 +810,9 @@ fn write_name( ctx.pop_format(idx); if let Some(suffix) = &name.suffix { + if comma_suffix { + ctx.push_str(sort_sep); + } ctx.ensure_space(); ctx.push_str(suffix); } diff --git a/src/csl/taxonomy.rs b/src/csl/taxonomy.rs index c03ec4ce..3388fa36 100644 --- a/src/csl/taxonomy.rs +++ b/src/csl/taxonomy.rs @@ -782,6 +782,7 @@ impl EntryLike for citationberg::json::Item { suffix: None, given_name: None, alias: None, + comma_suffix: false, }, csl_json::NameValue::Item(csl_json::NameItem { family, @@ -789,6 +790,7 @@ impl EntryLike for citationberg::json::Item { non_dropping_particle: None, dropping_particle: None, suffix, + comma_suffix, }) => { let mut parts = vec![family.as_str()]; if let Some(given) = given { @@ -798,6 +800,9 @@ impl EntryLike for citationberg::json::Item { if let Some(suffix) = suffix { p.suffix = Some(suffix.as_str().to_owned()); } + if comma_suffix.unwrap_or_default() { + p.comma_suffix = true; + } p } @@ -807,6 +812,7 @@ impl EntryLike for citationberg::json::Item { non_dropping_particle, dropping_particle, suffix, + comma_suffix, }) => Person { name: if let Some(non_drop) = non_dropping_particle { format!("{non_drop} {family}") @@ -817,6 +823,7 @@ impl EntryLike for citationberg::json::Item { suffix: suffix.clone(), given_name: given.clone(), alias: None, + comma_suffix: comma_suffix.unwrap_or_default(), }, })) }) diff --git a/src/interop.rs b/src/interop.rs index 3c737215..87a93771 100644 --- a/src/interop.rs +++ b/src/interop.rs @@ -50,6 +50,7 @@ impl From<&tex::Person> for Person { given_name: optional(&person.given_name), prefix: optional(&person.prefix), suffix: optional(&person.suffix), + comma_suffix: false, alias: None, } } diff --git a/src/types/persons.rs b/src/types/persons.rs index a3cfa266..aec2534d 100644 --- a/src/types/persons.rs +++ b/src/types/persons.rs @@ -97,6 +97,8 @@ derive_or_from_str! { pub prefix: Option, /// A suffix of the family name such as 'Jr.' or 'IV'. pub suffix: Option, + /// Whether a comma should be inserted before the suffix. + pub comma_suffix: bool, /// Another name (often user name) the person might be known under. pub alias: Option, } @@ -228,7 +230,14 @@ impl Person { name = name.trim_start().to_string(); } - Ok(Person { name, given_name, prefix, suffix, alias: None }) + Ok(Person { + name, + given_name, + prefix, + suffix, + comma_suffix: false, + alias: None, + }) } /// Formats the given name into initials. diff --git a/tests/citeproc-pass.txt b/tests/citeproc-pass.txt index 74787973..84d4794b 100644 --- a/tests/citeproc-pass.txt +++ b/tests/citeproc-pass.txt @@ -224,6 +224,7 @@ name_ArticularNameAsSortOrder name_ArticularPlain name_ArticularShortForm name_ArticularShortFormCommaSuffix +name_ArticularWithComma name_ArticularWithCommaNameAsSortOrder name_AsianGlyphs name_AuthorCountWithSameVarContentAndCombinedTermFail From 35b999d478336ac15e30a19535bd72b8e60f2f20 Mon Sep 17 00:00:00 2001 From: DerDrodt Date: Sun, 9 Nov 2025 14:27:49 +0100 Subject: [PATCH 2/2] Fix serde --- src/types/persons.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/types/persons.rs b/src/types/persons.rs index aec2534d..a62ec132 100644 --- a/src/types/persons.rs +++ b/src/types/persons.rs @@ -98,6 +98,7 @@ derive_or_from_str! { /// A suffix of the family name such as 'Jr.' or 'IV'. pub suffix: Option, /// Whether a comma should be inserted before the suffix. + #[serde(default)] pub comma_suffix: bool, /// Another name (often user name) the person might be known under. pub alias: Option,