git.iko.soy/typeable/pandoc
on master help sign in
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'.

commit6f99ad80135c06d30d92ad275d482e841ef1e872 authorJohn MacFarlane <fiddlosopher@gmail.com> dateSun 21 Jul 2013, 12:16 (13 years ago) parent800c549
1 file changed+15−7
src/Text/Pandoc/Biblio.hs+15−7
src/Text/Pandoc/Biblio.hs+15−7
@@ -119,12 +119,12 @@ toCslCite :: Citation -> CSL.Cite
119119toCslCite c
120120 = let (l, s) = locatorWords $ citationSuffix c
121121 (la,lo) = parseLocator l
122− s' = case (l,s,citationMode c) of
123− -- treat a bare locator as if it begins with comma
122+ s' = case (l,s) of
123+ -- treat a bare locator as if it begins with space
124124 -- so @item1 [blah] is like [@item1, blah]
125− ("",(x:_),AuthorInText) | not (isPunct x)
126− -> [Str ",",Space] ++ s
127− _ -> s
125+ ("",(x:_))
126+ | not (isPunct x) -> [Space] ++ s
127+ _ -> s
128128 isPunct (Str (x:_)) = isPunctuation x
129129 isPunct _ = False
130130 citMode = case citationMode c of
@@ -173,13 +173,21 @@ pLocator :: Parsec [Inline] st String
173173pLocator = try $ do
174174 optional $ pMatch (== Str ",")
175175 optional pSpace
176− f <- many1 (notFollowedBy pSpace >> anyToken)
176+ f <- (guardFollowingDigit >> return [Str "p"]) -- "page" the default
177+ <|> many1 (notFollowedBy pSpace >> anyToken)
177178 gs <- many1 pWordWithDigits
178179 return $ stringify f ++ (' ' : unwords gs)
179180
181+guardFollowingDigit :: Parsec [Inline] st ()
182+guardFollowingDigit = do
183+ t <- lookAhead anyToken
184+ case t of
185+ Str (d:_) | isDigit d -> return ()
186+ _ -> mzero
187+
180188pWordWithDigits :: Parsec [Inline] st String
181189pWordWithDigits = try $ do
182− pSpace
190+ optional pSpace
183191 r <- many1 (notFollowedBy pSpace >> anyToken)
184192 let s = stringify r
185193 guard $ any isDigit s