@@ -32,7 +32,7 @@ module Text.Pandoc.Biblio ( processBiblio ) where
3232import Data.List
3333import Data.Char ( isDigit, isPunctuation )
3434import qualified Data.Map as M
35−import Text.CSL hiding ( Cite(..), Citation(..) )
35+import Text.CSL hiding ( Cite(..), Citation(..), endWithPunct )
3636import qualified Text.CSL as CSL ( Cite(..) )
3737import Text.Pandoc.Definition
3838import Text.Pandoc.Generic
@@ -88,6 +88,19 @@ sanitize :: [Inline] -> [Inline]
8888sanitize xs | endWithPunct xs = toCapital xs
8989 | otherwise = toCapital (xs ++ [Str "."])
9090
91+
92+-- A replacement for citeproc-hs's endWithPunct, which wrongly treats
93+-- a sentence ending in '.)' as not ending with punctuation, leading
94+-- to an extra period.
95+endWithPunct :: [Inline] -> Bool
96+endWithPunct [] = True
97+endWithPunct xs@(_:_) = case reverse (stringify [last xs]) of
98+ [] -> True
99+ (')':c:_) | isEndPunct c -> True
100+ (c:_) | isEndPunct c -> True
101+ | otherwise -> False
102+ where isEndPunct c = c `elem` ".,;:!?"
103+
91104deNote :: Pandoc -> Pandoc
92105deNote = topDown go
93106 where go (Note [Para xs]) = Note $ bottomUp go' [Para $ sanitize xs]