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.
This commit is contained in:
John MacFarlane 2013-08-02 14:20:44 -07:00
parent 7024664dda
commit dceffeb043

View file

@ -32,7 +32,7 @@ module Text.Pandoc.Biblio ( processBiblio ) where
import Data.List
import Data.Char ( isDigit, isPunctuation )
import qualified Data.Map as M
import Text.CSL hiding ( Cite(..), Citation(..) )
import Text.CSL hiding ( Cite(..), Citation(..), endWithPunct )
import qualified Text.CSL as CSL ( Cite(..) )
import Text.Pandoc.Definition
import Text.Pandoc.Generic
@ -88,6 +88,19 @@ sanitize :: [Inline] -> [Inline]
sanitize xs | endWithPunct xs = toCapital xs
| otherwise = toCapital (xs ++ [Str "."])
-- A replacement for citeproc-hs's endWithPunct, which wrongly treats
-- a sentence ending in '.)' as not ending with punctuation, leading
-- to an extra period.
endWithPunct :: [Inline] -> Bool
endWithPunct [] = True
endWithPunct xs@(_:_) = case reverse (stringify [last xs]) of
[] -> True
(')':c:_) | isEndPunct c -> True
(c:_) | isEndPunct c -> True
| otherwise -> False
where isEndPunct c = c `elem` ".,;:!?"
deNote :: Pandoc -> Pandoc
deNote = topDown go
where go (Note [Para xs]) = Note $ bottomUp go' [Para $ sanitize xs]