From 4672f35143dad0772c1acbb226feba717ae1feca Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 22 Dec 2023 11:57:26 -0800 Subject: T.P.Chunks: Fine tune `makeChunks`. * Ensure that chunks not based on sections (those with the "preamble" class) get unique identifiers, by appending chunk number. * This will also ensure that they get unique path names when the path is generated from the identifier. Closes #9281. --- src/Text/Pandoc/Chunks.hs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Text/Pandoc/Chunks.hs b/src/Text/Pandoc/Chunks.hs index bd34cc6d5..566b10f8d 100644 --- a/src/Text/Pandoc/Chunks.hs +++ b/src/Text/Pandoc/Chunks.hs @@ -28,7 +28,8 @@ module Text.Pandoc.Chunks ) where import Text.Pandoc.Definition -import Text.Pandoc.Shared (makeSections, stringify, inlineListToIdentifier) +import Text.Pandoc.Shared (makeSections, stringify, inlineListToIdentifier, + tshow) import Text.Pandoc.Walk (Walkable(..)) import Data.Aeson (FromJSON, ToJSON) import Data.Text (Text) @@ -204,22 +205,26 @@ makeChunks chunklev pathTemplate meta = secsToChunks 1 divid (fromMaybe "" secnum) toChunk chunknum (Div ("",["preamble"],[]) bs) = - Chunk + Chunk { chunkHeading = docTitle meta - , chunkId = inlineListToIdentifier mempty $ docTitle meta + , chunkId = chunkid , chunkLevel = 0 , chunkNumber = chunknum , chunkSectionNumber = Nothing - , chunkPath = resolvePathTemplate pathTemplate chunknum - (stringify (docTitle meta)) - (inlineListToIdentifier mempty (docTitle meta)) - "0" + , chunkPath = chunkpath , chunkUp = Nothing , chunkPrev = Nothing , chunkNext = Nothing , chunkUnlisted = False , chunkContents = bs } + where + chunkpath = resolvePathTemplate pathTemplate chunknum + (stringify (docTitle meta)) + chunkid + "0" + chunkid = inlineListToIdentifier mempty (docTitle meta) <> + "-" <> tshow chunknum toChunk _ b = error $ "toChunk called on inappropriate block " <> show b -- should not happen -- cgit v1.2.3