aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2020-11-13 10:51:26 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2020-11-13 10:52:21 -0800
commit68b298ed9aee405033da9a2b44ae86f2241a123d (patch)
tree96a6274bdfad87d3cfea649a87c897f9075cc610 /src/Text/Pandoc
parentfec695c77aa77de89c7be205fb9c3a7271f57f12 (diff)
downloadpandoc-68b298ed9aee405033da9a2b44ae86f2241a123d.tar.gz
Improve period suppression algorithm for citations in notes...
in note citation styles. See #6835.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Citeproc.hs23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Citeproc.hs b/src/Text/Pandoc/Citeproc.hs
index a9f0b2d52..afcb2de5b 100644
--- a/src/Text/Pandoc/Citeproc.hs
+++ b/src/Text/Pandoc/Citeproc.hs
@@ -532,7 +532,9 @@ deNote (Note bs:rest) =
= 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 (Str t:_) = case T.uncons t of
+ Nothing -> False
+ Just (c,_) -> isUpper c
needsPeriod (Space:zs) = needsPeriod zs
needsPeriod _ = False
noteInParens (Note bs')
@@ -555,6 +557,25 @@ deNote (x:xs) = x : deNote xs
removeFinalPeriod :: [Inline] -> [Inline]
removeFinalPeriod ils =
case lastMay ils of
+ Just (Span attr ils')
+ -> initSafe ils ++ [Span attr (removeFinalPeriod ils')]
+ Just (Emph ils')
+ -> initSafe ils ++ [Emph (removeFinalPeriod ils')]
+ Just (Strong ils')
+ -> initSafe ils ++ [Strong (removeFinalPeriod ils')]
+ Just (SmallCaps ils')
+ -> initSafe ils ++ [SmallCaps (removeFinalPeriod ils')]
Just (Str t)
| T.takeEnd 1 t == "." -> initSafe ils ++ [Str (T.dropEnd 1 t)]
+ | isRightQuote (T.takeEnd 1 t)
+ -> removeFinalPeriod
+ (initSafe ils ++ [Str tInit | not (T.null tInit)]) ++ [Str tEnd]
+ where
+ tEnd = T.takeEnd 1 t
+ tInit = T.dropEnd 1 t
_ -> ils
+ where
+ isRightQuote "\8221" = True
+ isRightQuote "\8217" = True
+ isRightQuote "\187" = True
+ isRightQuote _ = False