aboutsummaryrefslogtreecommitdiff
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
parentfec695c77aa77de89c7be205fb9c3a7271f57f12 (diff)
downloadpandoc-68b298ed9aee405033da9a2b44ae86f2241a123d.tar.gz
Improve period suppression algorithm for citations in notes...
in note citation styles. See #6835.
-rw-r--r--src/Text/Pandoc/Citeproc.hs23
-rw-r--r--test/command/pandoc-citeproc-82.md4
2 files changed, 24 insertions, 3 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
diff --git a/test/command/pandoc-citeproc-82.md b/test/command/pandoc-citeproc-82.md
index 3464ae063..332140ed3 100644
--- a/test/command/pandoc-citeproc-82.md
+++ b/test/command/pandoc-citeproc-82.md
@@ -22,7 +22,7 @@ Title
Some text.[^1]
-[^1]: Comment regarding text, supported by citation [@OCLC_i1099]
+[^1]: Comment regarding text, supported by citation [@OCLC_i1099].
^D
Title
=====
@@ -36,5 +36,5 @@ OCLC. "WorldCat." Accessed September 19, 2014.
:::
:::
-[^1]: Comment regarding text, supported by citation (OCLC, "WorldCat.")
+[^1]: Comment regarding text, supported by citation (OCLC, "WorldCat").
```