From e6a1bb4b1fa655e4d69adadacbfbc4bc9a9c1939 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Thu, 3 Oct 2024 18:23:25 -0700 Subject: [PATCH] Reset docxListState if header has list information. See #10258. --- src/Text/Pandoc/Readers/Docx.hs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Text/Pandoc/Readers/Docx.hs b/src/Text/Pandoc/Readers/Docx.hs index 17d5b0809f6f..a3d724a0b1d3 100644 --- a/src/Text/Pandoc/Readers/Docx.hs +++ b/src/Text/Pandoc/Readers/Docx.hs @@ -691,6 +691,24 @@ bodyPartToBlocks (Paragraph pPr parparts) let addNum = if hasNumbering && isNothing (numbered pPr) then (++ ["unnumbered"]) else id + case numbered pPr of + Nothing -> pure () + Just Number{ numberNumId = numId + , numberLvl = lvl + , numberLvlInfo = levelInfo } -> do + -- We check whether this current numId has previously been used, + -- since Docx expects us to pick up where we left off. + listState <- gets docxListState + let startFromState = M.lookup (numId, lvl) listState + Level _ _ _ startFromLevelInfo = levelInfo + start = case startFromState of + Just x -> x + 1 + Nothing -> fromMaybe 1 startFromLevelInfo + modify $ \st -> st{ docxListState = + -- expire all the continuation data for lists of level > this one: + -- a new level 1 list item resets continuation for level 2+ + let notExpired (_, lvl') _ = lvl' <= lvl + in M.insert (numId, lvl) start (M.filterWithKey notExpired listState) } makeHeaderAnchor $ headerWith ("", addNum classes, []) n ils | Just Number{ numberNumId = numId