diff options
| author | John MacFarlane <[email protected]> | 2025-07-25 10:25:14 -0700 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2025-12-07 17:07:05 +0100 |
| commit | 7767011767eeccf1fb089a3c436f43a243d7da2e (patch) | |
| tree | 8cb2e7ce0b56019dc3e1e0cddfd4c6a73c834d25 /src | |
| parent | 7ced712014b64b59d39e07c82a1633109c05f730 (diff) | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Text/Pandoc/Citeproc.hs | 16 | ||||
| -rw-r--r-- | src/Text/Pandoc/Readers/EndNote.hs | 1 |
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 |
