summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2013-07-21 12:16:52 -0700
committerJohn MacFarlane <fiddlosopher@gmail.com>2013-07-21 12:16:52 -0700
commit6f99ad80135c06d30d92ad275d482e841ef1e872 (patch)
treea6c55a634c4b59c3bc5df312eeb759bee76f4bff /src
parent800c5490ec080520268c9c3348f2b4199a21e6db (diff)
Biblio: Tweaks to improve default behavior.
* A suffix beginning with a digit gets 'p' inserted before it before passing to citeproc-hs, so that bare numbers are treated as page numbers by default. * A suffix not beginning with punctuation has a space added at the beginning (rather than a comma and space, as was done before). * This adding occurs not just in author-in-text citations, but in all citations. The result of these changes (and the last commit) is that `\citep[23]{item1}` in LaTeX will be interpreted properly, with '23' treated as a locator of type 'page'.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Biblio.hs22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/Text/Pandoc/Biblio.hs b/src/Text/Pandoc/Biblio.hs
index 4dd82dd08..ae371a46d 100644
--- a/src/Text/Pandoc/Biblio.hs
+++ b/src/Text/Pandoc/Biblio.hs
@@ -119,12 +119,12 @@ toCslCite :: Citation -> CSL.Cite
toCslCite c
= let (l, s) = locatorWords $ citationSuffix c
(la,lo) = parseLocator l
- s' = case (l,s,citationMode c) of
- -- treat a bare locator as if it begins with comma
+ s' = case (l,s) of
+ -- treat a bare locator as if it begins with space
-- so @item1 [blah] is like [@item1, blah]
- ("",(x:_),AuthorInText) | not (isPunct x)
- -> [Str ",",Space] ++ s
- _ -> s
+ ("",(x:_))
+ | not (isPunct x) -> [Space] ++ s
+ _ -> s
isPunct (Str (x:_)) = isPunctuation x
isPunct _ = False
citMode = case citationMode c of
@@ -173,13 +173,21 @@ pLocator :: Parsec [Inline] st String
pLocator = try $ do
optional $ pMatch (== Str ",")
optional pSpace
- f <- many1 (notFollowedBy pSpace >> anyToken)
+ f <- (guardFollowingDigit >> return [Str "p"]) -- "page" the default
+ <|> many1 (notFollowedBy pSpace >> anyToken)
gs <- many1 pWordWithDigits
return $ stringify f ++ (' ' : unwords gs)
+guardFollowingDigit :: Parsec [Inline] st ()
+guardFollowingDigit = do
+ t <- lookAhead anyToken
+ case t of
+ Str (d:_) | isDigit d -> return ()
+ _ -> mzero
+
pWordWithDigits :: Parsec [Inline] st String
pWordWithDigits = try $ do
- pSpace
+ optional pSpace
r <- many1 (notFollowedBy pSpace >> anyToken)
let s = stringify r
guard $ any isDigit s