From 2b51f54e19373381df7f71f3094f97cc79dd82d2 Mon Sep 17 00:00:00 2001
From: John MacFarlane <jgm@berkeley.edu>
Date: Sat, 8 Jan 2022 16:54:00 -0800
Subject: [PATCH] toLocatorMap: store keys as lowercase.

We want to do a case-insensitive comparison when parsing
locators, so that e.g. both `Chap.` and `chap.` work.

Previously we lowercase terms when doing the lookup,
but they weren't lowercased in the map itself, which
led to locator-detection breaking for German (where the
terms have uppercase letters).

See
https://groups.google.com/d/msgid/pandoc-discuss/1dd44886-7b79-4e5f-97ec-57b91113df36n%40googlegroups.com
---
 src/Text/Pandoc/Citeproc/Locator.hs | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/Text/Pandoc/Citeproc/Locator.hs b/src/Text/Pandoc/Citeproc/Locator.hs
index 0b8f79922..35d5388b0 100644
--- a/src/Text/Pandoc/Citeproc/Locator.hs
+++ b/src/Text/Pandoc/Citeproc/Locator.hs
@@ -276,7 +276,9 @@ toLocatorMap locale =
   go tname locmap =
     case M.lookup tname (localeTerms locale) of
       Nothing -> locmap
-      Just ts -> foldr (\x -> M.insert (snd x) tname) locmap ts
+      Just ts -> foldr (\x -> M.insert (T.toCaseFold $ snd x) tname) locmap ts
+-- we store keys in "case-folded" (lowercase) form, so that both
+-- "Chap." and "chap." will match, for example.
 
 locatorTerms :: [Text]
 locatorTerms =