git.iko.soy/typeable/pandoc
on master help sign in
Biblio: Override citeproc-hs's endWithPunct.

The new version correctly sees a sentence ending in '.)' as ending with punctuation. This fixes a bug which led such sentences to receive an extra period at the end: '.).'. Thanks to Steve Petersen for reporting.

commitdceffeb04370e8661dd0534a6e97fd15caaeddcf authorJohn MacFarlane <jgm@berkeley.edu> dateFri 2 Aug 2013, 14:20 (13 years ago) parent7024664
1 file changed+14−1
src/Text/Pandoc/Biblio.hs+14−1
src/Text/Pandoc/Biblio.hs+14−1
@@ -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]