diff options
| author | John MacFarlane <jgm@berkeley.edu> | 2023-12-22 11:57:26 -0800 |
|---|---|---|
| committer | John MacFarlane <jgm@berkeley.edu> | 2023-12-22 11:57:26 -0800 |
| commit | 4672f35143dad0772c1acbb226feba717ae1feca (patch) | |
| tree | 50b5c19277121747b6552957ac6121dbdf5f16ed | |
| parent | 81521cee0da35a76a1181e06b83775ba2f94d295 (diff) | |
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.
| -rw-r--r-- | src/Text/Pandoc/Chunks.hs | 19 |
1 files 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 |
