@@ -27,7 +27,7 @@ import Text.Pandoc.Error (PandocError(..))
27import Text.Pandoc.Extensions (pandocExtensions)
27import Text.Pandoc.Extensions (pandocExtensions)
28import Text.Pandoc.Logging (LogMessage(..))
28import Text.Pandoc.Logging (LogMessage(..))
29import Text.Pandoc.Options (ReaderOptions(..))
29import Text.Pandoc.Options (ReaderOptions(..))
30−import Text.Pandoc.Shared (stringify, ordNub, tshow)
30+import Text.Pandoc.Shared (stringify, ordNub, blocksToInlines, tshow)
31import qualified Text.Pandoc.UTF8 as UTF8
31import qualified Text.Pandoc.UTF8 as UTF8
32import Text.Pandoc.Walk (query, walk, walkM)
32import Text.Pandoc.Walk (query, walk, walkM)
33import Control.Applicative ((<|>))
33import Control.Applicative ((<|>))
@@ -49,7 +49,6 @@ import qualified Data.Text as T
49import System.FilePath (takeExtension)
49import System.FilePath (takeExtension)
50import Safe (lastMay, initSafe)
50import Safe (lastMay, initSafe)
53processCitations :: PandocMonad m => Pandoc -> m Pandoc
52processCitations :: PandocMonad m => Pandoc -> m Pandoc
54processCitations (Pandoc meta bs) = do
53processCitations (Pandoc meta bs) = do
55 style <- getStyle (Pandoc meta bs)
54 style <- getStyle (Pandoc meta bs)
@@ -99,10 +98,8 @@ processCitations (Pandoc meta bs) = do
99 let metanocites = lookupMeta "nocite" meta
98 let metanocites = lookupMeta "nocite" meta
100 let Pandoc meta'' bs' =
99 let Pandoc meta'' bs' =
101 maybe id (setMeta "nocite") metanocites .
100 maybe id (setMeta "nocite") metanocites .
102− walk (mvPunct moveNotes locale) .
101+ walk (map capitalizeNoteCitation . mvPunct moveNotes locale) .
103− (if styleIsNoteStyle sopts
104− then walk addNote . walk deNote
102+ walk deNote .
106 evalState (walkM insertResolvedCitations $ Pandoc meta' bs)
103 evalState (walkM insertResolvedCitations $ Pandoc meta' bs)
108 return $ Pandoc meta''
105 return $ Pandoc meta''
@@ -564,62 +561,42 @@ extractText (FancyVal x) = toText x
564extractText (NumVal n) = T.pack (show n)
561extractText (NumVal n) = T.pack (show n)
565extractText _ = mempty
562extractText _ = mempty
567−-- Here we take the Spans with class csl-note that are left
568−-- after deNote has removed nested ones, and convert them
570−addNote :: Inline -> Inline
564+capitalizeNoteCitation :: Inline -> Inline
571−addNote (Span ("",["csl-note"],[]) ils) =
565+capitalizeNoteCitation (Cite cs [Note [Para ils]]) =
572− Note [Para $
566+ Cite cs
573− B.toList . addTextCase Nothing CapitalizeFirst . B.fromList $ ils]
567+ [Note [Para $ B.toList $ addTextCase Nothing CapitalizeFirst
574−addNote x = x
568+ $ B.fromList ils]]
575−
569+capitalizeNoteCitation x = x
576−-- Here we handle citation notes that occur inside footnotes
570+
577−-- or other citation notes, in a note style. We don't want
578−-- notes inside notes, so we convert these to parenthesized
579−-- or comma-separated citations.
580−deNote :: Inline -> Inline
571+deNote :: [Inline] -> [Inline]
581−deNote (Note bs) =
572+deNote [] = []
582− case bs of
573+deNote (Note bs:rest) =
583− [Para (cit@(Cite (c:_) _) : ils)]
574+ Note (walk go bs) : deNote rest
584− | citationMode c /= AuthorInText ->
585− -- if citation is first in note, no need to parenthesize.
586− Note [Para (walk removeNotes $ cit : walk addParens ils)]
587− _ -> Note (walk removeNotes . walk addParens $ bs)
590− addParens [] = []
576+ go [] = []
591− addParens (Cite (c:cs) ils : zs)
577+ go (Cite (c:cs) ils : zs)
592 | citationMode c == AuthorInText
578 | citationMode c == AuthorInText
593− = Cite (c:cs) (concatMap (noteAfterComma (needsPeriod zs)) ils) :
579+ = Cite (c:cs) (concatMap (noteAfterComma (needsPeriod zs)) ils) : go zs
595 | otherwise
580 | otherwise
596− = Cite (c:cs) (concatMap noteInParens ils) : addParens zs
581+ = Cite (c:cs) (concatMap noteInParens ils) : go zs
597− addParens (x:xs) = x : addParens xs
582+ go (x:xs) = x : go xs
599− removeNotes (Span ("",["csl-note"],[]) ils) = Span ("",[],[]) ils
602 needsPeriod [] = True
583 needsPeriod [] = True
603 needsPeriod (Str t:_) = case T.uncons t of
584 needsPeriod (Str t:_) = case T.uncons t of
604 Nothing -> False
585 Nothing -> False
605 Just (c,_) -> isUpper c
586 Just (c,_) -> isUpper c
606 needsPeriod (Space:zs) = needsPeriod zs
587 needsPeriod (Space:zs) = needsPeriod zs
607 needsPeriod _ = False
588 needsPeriod _ = False
609− noteInParens (Span ("",["csl-note"],[]) ils)
589+ noteInParens (Note bs')
610 = Space : Str "(" :
590 = Space : Str "(" :
611− removeFinalPeriod ils ++ [Str ")"]
591+ removeFinalPeriod (blocksToInlines bs') ++ [Str ")"]
612 noteInParens x = [x]
592 noteInParens x = [x]
614− noteAfterComma needsPer (Span ("",["csl-note"],[]) ils)
593+ noteAfterComma needsPer (Note bs')
616 = Str "," : Space :
594 = Str "," : Space :
617− if needsPer
595+ (if needsPer
618− then ils
596+ then id
619− else removeFinalPeriod ils
597+ else removeFinalPeriod) (blocksToInlines bs')
620 noteAfterComma _ x = [x]
598 noteAfterComma _ x = [x]
622−deNote x = x
599+deNote (x:xs) = x : deNote xs
624-- Note: we can't use dropTextWhileEnd indiscriminately,
601-- Note: we can't use dropTextWhileEnd indiscriminately,
625-- because this would remove the final period on abbreviations like Ibid.
602-- because this would remove the final period on abbreviations like Ibid.