aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2025-07-25 10:25:14 -0700
committerJohn MacFarlane <[email protected]>2025-12-06 18:33:17 +0100
commit28d3dbfec97b9cdccf16fb63042380c2ef89cb63 (patch)
treec7389cf40d900cbeed16d58227bc5ab0159cb317 /src/Text/Pandoc
parent7ced712014b64b59d39e07c82a1633109c05f730 (diff)
Implement `reset-citation-positions` class on headings.reset-position
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.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Citeproc.hs16
-rw-r--r--src/Text/Pandoc/Readers/EndNote.hs1
2 files changed, 15 insertions, 2 deletions
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