git.iko.soy/typeable/pandoc
on master help sign in
Biblio: Override citeproc-hs's endWithPunct.
dceffebJohn MacFarlane
src/Text/Pandoc/Biblio.hs+14−1
@@ -32,7 +32,7 @@ module Text.Pandoc.Biblio ( processBiblio ) where
32import Data.List
32import Data.List
33import Data.Char ( isDigit, isPunctuation )
33import Data.Char ( isDigit, isPunctuation )
34import qualified Data.Map as M
34import qualified Data.Map as M
35−import Text.CSL hiding ( Cite(..), Citation(..) )
35+import Text.CSL hiding ( Cite(..), Citation(..), endWithPunct )
36import qualified Text.CSL as CSL ( Cite(..) )
36import qualified Text.CSL as CSL ( Cite(..) )
37import Text.Pandoc.Definition
37import Text.Pandoc.Definition
38import Text.Pandoc.Generic
38import Text.Pandoc.Generic
@@ -88,6 +88,19 @@ sanitize :: [Inline] -> [Inline]
88sanitize xs | endWithPunct xs = toCapital xs
88sanitize xs | endWithPunct xs = toCapital xs
89 | otherwise = toCapital (xs ++ [Str "."])
89 | otherwise = toCapital (xs ++ [Str "."])
90
90
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+
91deNote :: Pandoc -> Pandoc
104deNote :: Pandoc -> Pandoc
92deNote = topDown go
105deNote = topDown go
93 where go (Note [Para xs]) = Note $ bottomUp go' [Para $ sanitize xs]
106 where go (Note [Para xs]) = Note $ bottomUp go' [Para $ sanitize xs]