@@ -20,7 +20,7 @@ parseLocator :: Locale -> [Inline] -> (Maybe (Text, Text), [Inline])
2020parseLocator locale inp =
2121 case parse (pLocatorWords (toLocatorMap locale)) "suffix" $ splitInp inp of
2222 Right r -> r
23− Left _ -> (Nothing, inp)
23+ Left _ -> (Nothing, maybeAddComma inp)
2424
2525splitInp :: [Inline] -> [Inline]
2626splitInp = splitStrWhen (\c -> isSpace c || (isPunctuation c && c /= ':'))
@@ -42,9 +42,17 @@ pLocatorWords locMap = do
4242 -- i.e. the first one will be " 9"
4343 return $
4444 if T.null la && T.null lo
45− then (Nothing, s)
45+ then (Nothing, maybeAddComma s)
4646 else (Just (la, T.strip lo), s)
4747
48+maybeAddComma :: [Inline] -> [Inline]
49+maybeAddComma [] = []
50+maybeAddComma ils@(Space : _) = ils
51+maybeAddComma ils@(Str t : _)
52+ | Just (c, _) <- T.uncons t
53+ , isPunctuation c = ils
54+maybeAddComma ils = Str "," : Space : ils
55+
4856pLocatorDelimited :: LocatorMap -> LocatorParser (Text, Text)
4957pLocatorDelimited locMap = try $ do
5058 _ <- pMatchChar "{" (== '{')
@@ -97,7 +105,7 @@ pLocatorLabel' locMap lim = go ""
97105 t <- anyToken
98106 ts <- manyTill anyToken (try $ lookAhead lim)
99107 let s = acc <> stringify (t:ts)
100− case M.lookup (T.strip s) locMap of
108+ case M.lookup (T.toCaseFold $ T.strip s) locMap of
101109 -- try to find a longer one, or return this one
102110 Just l -> go s <|> return (l, False)
103111 Nothing -> go s