Skip to content

Commit

Permalink
Citeproc: improve punctuation in in-text note citations.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jgm committed Nov 5, 2020
1 parent efe7474 commit 090b087
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/Text/Pandoc/Citeproc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 090b087

Please sign in to comment.