From dceffeb04370e8661dd0534a6e97fd15caaeddcf Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 2 Aug 2013 14:20:44 -0700 Subject: 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. --- src/Text/Pandoc/Biblio.hs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Text/Pandoc/Biblio.hs b/src/Text/Pandoc/Biblio.hs index ae371a46d..31c55472e 100644 --- a/src/Text/Pandoc/Biblio.hs +++ b/src/Text/Pandoc/Biblio.hs @@ -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] -- cgit v1.2.3