From 28d3dbfec97b9cdccf16fb63042380c2ef89cb63 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 25 Jul 2025 10:25:14 -0700 Subject: 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. --- src/Text/Pandoc/Citeproc.hs | 16 ++++++++++++++-- src/Text/Pandoc/Readers/EndNote.hs | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) (limited to 'src/Text') 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 -- cgit v1.2.3