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.
This commit is contained in:
parent
4b16d181e7
commit
4842c5fb82
3 changed files with 65 additions and 3 deletions
|
@ -20,7 +20,7 @@ parseLocator :: Locale -> [Inline] -> (Maybe (Text, Text), [Inline])
|
|||
parseLocator locale inp =
|
||||
case parse (pLocatorWords (toLocatorMap locale)) "suffix" $ splitInp inp of
|
||||
Right r -> r
|
||||
Left _ -> (Nothing, inp)
|
||||
Left _ -> (Nothing, maybeAddComma inp)
|
||||
|
||||
splitInp :: [Inline] -> [Inline]
|
||||
splitInp = splitStrWhen (\c -> isSpace c || (isPunctuation c && c /= ':'))
|
||||
|
@ -42,9 +42,17 @@ pLocatorWords locMap = do
|
|||
-- i.e. the first one will be " 9"
|
||||
return $
|
||||
if T.null la && T.null lo
|
||||
then (Nothing, s)
|
||||
then (Nothing, maybeAddComma s)
|
||||
else (Just (la, T.strip lo), s)
|
||||
|
||||
maybeAddComma :: [Inline] -> [Inline]
|
||||
maybeAddComma [] = []
|
||||
maybeAddComma ils@(Space : _) = ils
|
||||
maybeAddComma ils@(Str t : _)
|
||||
| Just (c, _) <- T.uncons t
|
||||
, isPunctuation c = ils
|
||||
maybeAddComma ils = Str "," : Space : ils
|
||||
|
||||
pLocatorDelimited :: LocatorMap -> LocatorParser (Text, Text)
|
||||
pLocatorDelimited locMap = try $ do
|
||||
_ <- pMatchChar "{" (== '{')
|
||||
|
@ -97,7 +105,7 @@ pLocatorLabel' locMap lim = go ""
|
|||
t <- anyToken
|
||||
ts <- manyTill anyToken (try $ lookAhead lim)
|
||||
let s = acc <> stringify (t:ts)
|
||||
case M.lookup (T.strip s) locMap of
|
||||
case M.lookup (T.toCaseFold $ T.strip s) locMap of
|
||||
-- try to find a longer one, or return this one
|
||||
Just l -> go s <|> return (l, False)
|
||||
Nothing -> go s
|
||||
|
|
29
test/command/7323.md
Normal file
29
test/command/7323.md
Normal file
|
@ -0,0 +1,29 @@
|
|||
```
|
||||
% pandoc --citeproc -t plain
|
||||
---
|
||||
references:
|
||||
- id: smith
|
||||
author: John Smith
|
||||
issued: 2019
|
||||
title: Insects
|
||||
type: book
|
||||
...
|
||||
|
||||
@smith [chap. 6]
|
||||
|
||||
@smith [chapter 6]
|
||||
|
||||
@smith [Chap. 6]
|
||||
|
||||
@smith [Chapter 6]
|
||||
^D
|
||||
John Smith (2019, chap. 6)
|
||||
|
||||
John Smith (2019, chap. 6)
|
||||
|
||||
John Smith (2019, chap. 6)
|
||||
|
||||
John Smith (2019, chap. 6)
|
||||
|
||||
John Smith. 2019. Insects.
|
||||
```
|
25
test/command/7324.md
Normal file
25
test/command/7324.md
Normal file
|
@ -0,0 +1,25 @@
|
|||
```
|
||||
% pandoc --citeproc -t plain
|
||||
---
|
||||
references:
|
||||
- id: smith
|
||||
author: John Smith
|
||||
issued: 2019
|
||||
title: Insects
|
||||
type: book
|
||||
...
|
||||
|
||||
@smith [, among others]
|
||||
|
||||
@smith [ among others]
|
||||
|
||||
@smith [among others]
|
||||
^D
|
||||
John Smith (2019, among others)
|
||||
|
||||
John Smith (2019 among others)
|
||||
|
||||
John Smith (2019, among others)
|
||||
|
||||
John Smith. 2019. Insects.
|
||||
```
|
Loading…
Add table
Reference in a new issue