diff options
-rw-r--r-- | cabal.project | 2 | ||||
-rw-r--r-- | src/Text/Pandoc/Citeproc.hs | 44 | ||||
-rw-r--r-- | stack.yaml | 2 |
3 files changed, 32 insertions, 16 deletions
diff --git a/cabal.project b/cabal.project index 99c7b3556..e18577471 100644 --- a/cabal.project +++ b/cabal.project @@ -10,4 +10,4 @@ source-repository-package source-repository-package type: git location: https://github.com/jgm/citeproc - tag: 85277c4baa6c0350baf29247583ae0f438f7c9c5 + tag: 4ce0501cd6f9c86eee087afcf878c256e49b9615 diff --git a/src/Text/Pandoc/Citeproc.hs b/src/Text/Pandoc/Citeproc.hs index a2fca106a..b19494dc0 100644 --- a/src/Text/Pandoc/Citeproc.hs +++ b/src/Text/Pandoc/Citeproc.hs @@ -27,7 +27,7 @@ import Text.Pandoc.Error (PandocError(..)) import Text.Pandoc.Extensions (pandocExtensions) import Text.Pandoc.Logging (LogMessage(..)) import Text.Pandoc.Options (ReaderOptions(..)) -import Text.Pandoc.Shared (stringify, ordNub, blocksToInlines, tshow) +import Text.Pandoc.Shared (stringify, ordNub, tshow) import qualified Text.Pandoc.UTF8 as UTF8 import Text.Pandoc.Walk (query, walk, walkM) import Control.Applicative ((<|>)) @@ -49,6 +49,7 @@ import qualified Data.Text as T import System.FilePath (takeExtension) import Safe (lastMay, initSafe) + processCitations :: PandocMonad m => Pandoc -> m Pandoc processCitations (Pandoc meta bs) = do style <- getStyle (Pandoc meta bs) @@ -99,7 +100,9 @@ processCitations (Pandoc meta bs) = do let Pandoc meta'' bs' = maybe id (setMeta "nocite") metanocites . walk (map capitalizeNoteCitation . mvPunct moveNotes locale) . - walk deNote . + (if styleIsNoteStyle sopts + then walk addNote . walk deNote + else id) . evalState (walkM insertResolvedCitations $ Pandoc meta' bs) $ cits return $ Pandoc meta'' @@ -568,33 +571,46 @@ capitalizeNoteCitation (Cite cs [Note [Para ils]]) = $ B.fromList ils]] capitalizeNoteCitation x = x +addNote :: Inline -> Inline +addNote (Span ("",["csl-note"],[]) ils) = Note [Para ils] +addNote x = x + deNote :: [Inline] -> [Inline] deNote [] = [] deNote (Note bs:rest) = - Note (walk go bs) : deNote rest + case bs of + [Para (cit@(Cite (c:_) _) : ils)] + | citationMode c /= AuthorInText -> + -- if citation is first in note, no need to parenthesize. + Note [Para (walk removeNotes $ cit : walk addParens ils)] + : deNote rest + _ -> Note (walk removeNotes . walk addParens $ bs) : deNote rest where - go [] = [] - go (Cite (c:cs) ils : zs) + addParens [] = [] + addParens (Cite (c:cs) ils : zs) | citationMode c == AuthorInText - = Cite (c:cs) (concatMap (noteAfterComma (needsPeriod zs)) ils) : go zs + = Cite (c:cs) (concatMap (noteAfterComma (needsPeriod zs)) ils) : + addParens zs | otherwise - = Cite (c:cs) (concatMap noteInParens ils) : go zs - go (x:xs) = x : go xs + = Cite (c:cs) (concatMap noteInParens ils) : addParens zs + addParens (x:xs) = x : addParens xs + removeNotes (Span ("",["csl-note"],[]) ils) = Span ("",[],[]) ils + removeNotes x = x needsPeriod [] = True needsPeriod (Str t:_) = case T.uncons t of Nothing -> False Just (c,_) -> isUpper c needsPeriod (Space:zs) = needsPeriod zs needsPeriod _ = False - noteInParens (Note bs') + noteInParens (Span ("",["csl-note"],[]) ils) = Space : Str "(" : - removeFinalPeriod (blocksToInlines bs') ++ [Str ")"] + removeFinalPeriod ils ++ [Str ")"] noteInParens x = [x] - noteAfterComma needsPer (Note bs') + noteAfterComma needsPer (Span ("",["csl-note"],[]) ils) = Str "," : Space : - (if needsPer - then id - else removeFinalPeriod) (blocksToInlines bs') + if needsPer + then ils + else removeFinalPeriod ils noteAfterComma _ x = [x] deNote (x:xs) = x : deNote xs diff --git a/stack.yaml b/stack.yaml index 2db0a626f..48a608db3 100644 --- a/stack.yaml +++ b/stack.yaml @@ -14,7 +14,7 @@ extra-deps: - git: https://github.com/jgm/doctemplates commit: 428c26d5303cf7a2b1051fe1ffd9aafe9ba71c81 - git: https://github.com/jgm/citeproc - commit: 85277c4baa6c0350baf29247583ae0f438f7c9c5 + commit: 4ce0501cd6f9c86eee087afcf878c256e49b9615 ghc-options: "$locals": -fhide-source-paths -Wno-missing-home-modules resolver: lts-18.0 |