aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Citeproc.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2020-11-05 11:15:23 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2020-11-05 11:15:23 -0800
commit090b0877bc6a50e77deae15ac6659875b9bf29ce (patch)
tree4be4a6d177114a86aea1ea594be13ab080b7eb6b /src/Text/Pandoc/Citeproc.hs
parentefe74746d881828723d2af79d1097794a21aee54 (diff)
downloadpandoc-090b0877bc6a50e77deae15ac6659875b9bf29ce.tar.gz
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.
Diffstat (limited to 'src/Text/Pandoc/Citeproc.hs')
-rw-r--r--src/Text/Pandoc/Citeproc.hs23
1 files 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,