From 6f99ad80135c06d30d92ad275d482e841ef1e872 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sun, 21 Jul 2013 12:16:52 -0700 Subject: 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'. --- src/Text/Pandoc/Biblio.hs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'src/Text/Pandoc') 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 -- cgit v1.2.3