git.iko.soy/typeable/pandoc
on master help sign in
Two citeproc locator/suffix improvements:

- Recognize locators spelled with a capital letter. Closes #7323. - Add a comma and a space in front of the suffix if it doesn't start with space or punctuation. Closes #7324.

commit4842c5fb828c3c34d816fa7bccd4656857742a0b authorJohn MacFarlane <jgm@berkeley.edu> dateThu 27 May 2021, 18:28 (5 years ago) parent4b16d18
3 files changed+65−3
src/Text/Pandoc/Citeproc/Locator.hs+11−3 test/command/7323.md+29 test/command/7324.md+25
src/Text/Pandoc/Citeproc/Locator.hs+11−3
@@ -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
test/command/7323.mdnew file+29
@@ -0,0 +1,29 @@
1+```
2+% pandoc --citeproc -t plain
3+---
4+references:
5+- id: smith
6+ author: John Smith
7+ issued: 2019
8+ title: Insects
9+ type: book
10+...
11+
12+@smith [chap. 6]
13+
14+@smith [chapter 6]
15+
16+@smith [Chap. 6]
17+
18+@smith [Chapter 6]
19+^D
20+John Smith (2019, chap. 6)
21+
22+John Smith (2019, chap. 6)
23+
24+John Smith (2019, chap. 6)
25+
26+John Smith (2019, chap. 6)
27+
28+John Smith. 2019. Insects.
29+```
test/command/7324.mdnew file+25
@@ -0,0 +1,25 @@
1+```
2+% pandoc --citeproc -t plain
3+---
4+references:
5+- id: smith
6+ author: John Smith
7+ issued: 2019
8+ title: Insects
9+ type: book
10+...
11+
12+@smith [, among others]
13+
14+@smith [ among others]
15+
16+@smith [among others]
17+^D
18+John Smith (2019, among others)
19+
20+John Smith (2019 among others)
21+
22+John Smith (2019, among others)
23+
24+John Smith. 2019. Insects.
25+```