aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2013-08-02 14:20:44 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2013-08-02 14:20:44 -0700
commitdceffeb04370e8661dd0534a6e97fd15caaeddcf (patch)
tree3dabaee6c9d5b4a00a3f8e8cc4a1232515daf3da
parent7024664ddae00fc459953bb5d4bbc91d5877be1b (diff)
downloadpandoc-dceffeb04370e8661dd0534a6e97fd15caaeddcf.tar.gz
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.
-rw-r--r--src/Text/Pandoc/Biblio.hs15
1 files changed, 14 insertions, 1 deletions
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]