Implement reset-citation-positions class on headings.

When the `reset-citation-positions` class is added to
a top-level heading, `--citeproc` will reset position
information at that point in the document. This is needed
in order to ensure that the first citation in a chapter
to a work that has been cited in a previous chapter will
not be in abbreviated form.

Requires a dependency on a development version of citeproc.
This commit is contained in:
John MacFarlane
2025-07-25 10:25:14 -07:00
parent 7ced712014
commit 28d3dbfec9
6 changed files with 74 additions and 2 deletions
+11
View File
@@ -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
+5
View File
@@ -12,6 +12,11 @@ source-repository-package
location: https://github.com/jgm/asciidoc-hs.git
tag: c2b4852e0002a7995793ec0e3c44b723a85a2ca2
source-repository-package
type: git
location: https://github.com/jgm/citeproc.git
tag: 6e1028d3dde5fdfc5225f445f7293649b59df0b1
source-repository-package
type: git
location: https://github.com/jgm/typst-hs.git
+14 -2
View File
@@ -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 =
+1
View File
@@ -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
+2
View File
@@ -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
tag: 6e1028d3dde5fdfc5225f445f7293649b59df0b1
ghc-options:
"$locals": -fhide-source-paths -Wno-missing-home-modules
resolver: lts-24.20
+41
View File
@@ -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.
```