From f9f809f7014a0171ed2621fade1fc016204e70dd Mon Sep 17 00:00:00 2001 From: funkpower Date: Sun, 20 Sep 2026 07:18:34 -0400 Subject: [PATCH] chunkmd: the half of a word boundary that applies before a digit --- crates/chunkmd/src/footnote.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/crates/chunkmd/src/footnote.rs b/crates/chunkmd/src/footnote.rs index 2b9ca7d..88cd953 100644 --- a/crates/chunkmd/src/footnote.rs +++ b/crates/chunkmd/src/footnote.rs @@ -66,10 +66,17 @@ static NOTE_MARKER: LazyLock = LazyLock::new(|| { }); /// What makes a note bibliographic rather than discursive. +/// What a citation looks like inside a note entry. +/// +/// The year alternative wants Python's `\b`, which is true when exactly one +/// side is a word character. What follows it here is a digit, so the half +/// that applies is the one asserting the character *before* is not a word +/// character. `WORD_END` would ask the opposite and refuse `(1740-1811)`, +/// where the year is preceded by a dash and a date. static CITE_SIGNAL: LazyLock = LazyLock::new(|| { FancyRegex::new(&format!( r"(?ix) - \((?:[^()]*{WORD_END})?(?:1[5-9]|20)\d{{2}}\) # parenthesised year: (Oxford, 1998) + \((?:[^()]*{WORD_START})?(?:1[5-9]|20)\d{{2}}\) # parenthesised year: (Oxford, 1998) | {WORD_START}pp?\.{SPACE}*\d # p. 12 / pp. 12-34 | {WORD_START}vol\.{SPACE}*\d # vol. 2 | {WORD_START}Ibid{WORD_END} @@ -134,6 +141,20 @@ mod tests { assert!(looks_like_citations(&format!("{SENTINEL}See above."))); } + #[test] + fn a_year_preceded_by_a_dash_is_still_a_citation() { + // `(1740\u{2013}1811)` and `(Niter\u{f3}i, 1860\u{2013}1937)`: the year is + // preceded by a character that is not a word character, which is the + // half of a word boundary that applies when what follows is a digit. + // Both are real entries out of a converted book, where the + // parenthesised year was the only citation signal in the chunk. + let notes = "11\\. Tiradentes was a hero. In this painting by Ant\u{f4}nio Parreiras \ + (Niter\u{f3}i, 1860\u{2013}1937), he is immortalized.\n\n\ + 12\\. Many peoples came from Africa. Carlos Juli\u{e3}o \ + (1740\u{2013}1811) was a Portuguese-Italian artist.\n"; + assert!(looks_like_citations(notes)); + } + #[test] fn two_numbered_notes_with_citation_signals_count() { let text = "12. Arendt, The Human Condition (Chicago, 1958), 44.\n\