diff options
| -rw-r--r-- | MANUAL.txt | 11 | ||||
| -rw-r--r-- | cabal.project | 5 | ||||
| -rw-r--r-- | src/Text/Pandoc/Citeproc.hs | 16 | ||||
| -rw-r--r-- | src/Text/Pandoc/Readers/EndNote.hs | 1 | ||||
| -rw-r--r-- | stack.yaml | 2 | ||||
| -rw-r--r-- | test/command/reset-citation-positions.md | 41 |
6 files changed, 74 insertions, 2 deletions
diff --git a/MANUAL.txt b/MANUAL.txt index 91f1c8e7f..f712eb68b 100644 --- a/MANUAL.txt +++ b/MANUAL.txt @@ -5992,6 +5992,17 @@ parentheses, while author-in-text citations will not. For this reason, it is sometimes preferable to use the author-in-text style inside notes when using a note style. +Many CSL styles will format citations differently when the +same source has been cited earlier. In documents with chapters, +it is usually desirable to reset this position information +at the beginning of every chapter. To do this, add the class +`reset-citation-positions` to the heading for each chapter: + + # The Beginning {.reset-citation-positions} + +Note that this class only has an effect when placed on +top-level headings; it is ignored in nested blocks. + [CSL user documentation]: https://citationstyles.org/authors/ [CSL]: https://docs.citationstyles.org/en/stable/specification.html [CSL markup specs]: https://citeproc-js.readthedocs.io/en/latest/csl-json/markup.html#html-like-formatting-tags diff --git a/cabal.project b/cabal.project index fb9f2d2a3..b275b3ba7 100644 --- a/cabal.project +++ b/cabal.project @@ -14,5 +14,10 @@ source-repository-package source-repository-package type: git + location: https://github.com/jgm/citeproc.git + tag: 777a916be683a40e9b5e17da25816917b6fb1208 + +source-repository-package + type: git location: https://github.com/jgm/typst-hs.git tag: 9b10ff32492304867b6cc410db6e843c2c9b913b diff --git a/src/Text/Pandoc/Citeproc.hs b/src/Text/Pandoc/Citeproc.hs index f10761136..43cd34571 100644 --- a/src/Text/Pandoc/Citeproc.hs +++ b/src/Text/Pandoc/Citeproc.hs @@ -30,7 +30,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, tshow) +import Text.Pandoc.Shared (stringify, tshow, makeSections) import Data.Containers.ListUtils (nubOrd) import Text.Pandoc.Walk (query, walk, walkM) import Control.Applicative ((<|>)) @@ -295,10 +295,22 @@ getCitations :: Locale -> M.Map Text ItemId -> Pandoc -> [Citeproc.Citation Inlines] -getCitations locale otherIdsMap = Foldable.toList . query getCitation +getCitations locale otherIdsMap (Pandoc meta blocks) = + Foldable.toList (query getCitation meta <> + foldMap handleBlock (makeSections False Nothing blocks)) where + handleBlock :: Block -> Seq.Seq (Citeproc.Citation Inlines) + handleBlock b@(Div (_,cls,_) _) + | "section" `elem` cls + , "reset-citation-positions" `elem` cls = + case Seq.viewl (query getCitation b) of + x Seq.:< xs -> addResetTo x Seq.<| xs + Seq.EmptyL -> mempty + handleBlock b = query getCitation b + addResetTo citation = citation{ Citeproc.citationResetPosition = True } getCitation (Cite cs _fallback) = Seq.singleton $ Citeproc.Citation { Citeproc.citationId = Nothing + , Citeproc.citationResetPosition = False , Citeproc.citationPrefix = Nothing , Citeproc.citationSuffix = Nothing , Citeproc.citationNoteNumber = diff --git a/src/Text/Pandoc/Readers/EndNote.hs b/src/Text/Pandoc/Readers/EndNote.hs index f0f22338d..f595c7684 100644 --- a/src/Text/Pandoc/Readers/EndNote.hs +++ b/src/Text/Pandoc/Readers/EndNote.hs @@ -81,6 +81,7 @@ readEndNoteXMLCitation xml = do let items = map toCitationItem $ filterElementsName (name "Cite") tree return $ Citeproc.Citation{ Citeproc.citationId = Nothing + , Citeproc.citationResetPosition = False , Citeproc.citationPrefix = Nothing , Citeproc.citationSuffix = Nothing , Citeproc.citationNoteNumber = Nothing diff --git a/stack.yaml b/stack.yaml index f54de02ea..7b59fc4db 100644 --- a/stack.yaml +++ b/stack.yaml @@ -21,6 +21,8 @@ extra-deps: commit: c2b4852e0002a7995793ec0e3c44b723a85a2ca2 - git: https://github.com/jgm/typst-hs.git commit: 9b10ff32492304867b6cc410db6e843c2c9b913b +- git: https://github.com/jgm/citeproc.git + commit: 777a916be683a40e9b5e17da25816917b6fb1208 ghc-options: "$locals": -fhide-source-paths -Wno-missing-home-modules resolver: lts-24.20 diff --git a/test/command/reset-citation-positions.md b/test/command/reset-citation-positions.md new file mode 100644 index 000000000..e6ed125d0 --- /dev/null +++ b/test/command/reset-citation-positions.md @@ -0,0 +1,41 @@ +``` +% pandoc --citeproc -t plain --csl command/chicago-fullnote-bibliography.csl +--- +suppress-bibliography: true +references: +- id: foo + name: John doe + title: A Book + type: book + publisher: Oxford University Press + issued: 2010 +... + +# Chapter one + +Blah [@foo, p. 7]. + +Blah [@foo, p. 8]. + +# Chapter two {.reset-citation-positions} + +Blah [@foo, p. 57]. +^D +Chapter one + +Blah.[1] + +Blah.[2] + +Chapter two + +Blah.[3] + +[1] A Book (Oxford University Press, 2010), 7. + +[2] A Book, 8. + +[3] A Book (Oxford University Press, 2010), 57. + +``` + |
