From 090b0877bc6a50e77deae15ac6659875b9bf29ce Mon Sep 17 00:00:00 2001 From: John MacFarlane <jgm@berkeley.edu> Date: Thu, 5 Nov 2020 11:15:23 -0800 Subject: [PATCH] Citeproc: improve punctuation in in-text note citations. Previously in-text note citations inside a footnote would sometimes have the final period stripped, even if it was needed (e.g. on the end of 'ibid'). See #6813. --- src/Text/Pandoc/Citeproc.hs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/Text/Pandoc/Citeproc.hs b/src/Text/Pandoc/Citeproc.hs index 892e49c22..541e9df94 100644 --- a/src/Text/Pandoc/Citeproc.hs +++ b/src/Text/Pandoc/Citeproc.hs @@ -35,7 +35,7 @@ import Data.Default import Data.Ord () import qualified Data.Map as M import qualified Data.Set as Set -import Data.Char (isPunctuation) +import Data.Char (isPunctuation, isUpper) import Data.Text (Text) import qualified Data.Text as T import Control.Monad.State @@ -528,20 +528,27 @@ deNote [] = [] deNote (Note bs:rest) = Note (walk go bs) : deNote rest where - go (Cite (c:cs) ils) + go [] = [] + go (Cite (c:cs) ils : zs) | citationMode c == AuthorInText - = Cite cs (concatMap noteAfterComma ils) + = Cite cs (concatMap (noteAfterComma (needsPeriod zs)) ils) : go zs | otherwise - = Cite cs (concatMap noteInParens ils) - go x = x + = Cite cs (concatMap noteInParens ils) : go zs + go (x:xs) = x : go xs + needsPeriod [] = True + needsPeriod (Str t:_) = not (T.null t) && isUpper (T.head t) + needsPeriod (Space:zs) = needsPeriod zs + needsPeriod _ = False noteInParens (Note bs') = Space : Str "(" : removeFinalPeriod (blocksToInlines bs') ++ [Str ")"] noteInParens x = [x] - noteAfterComma (Note bs') + noteAfterComma needsPer (Note bs') = Str "," : Space : - removeFinalPeriod (blocksToInlines bs') - noteAfterComma x = [x] + (if needsPer + then id + else removeFinalPeriod) (blocksToInlines bs') + noteAfterComma _ x = [x] deNote (x:xs) = x : deNote xs -- Note: we can't use dropTextWhileEnd indiscriminately,