git.iko.soy/typeable/pandoc
on master help sign in
Docx writer: Continue lists after interruption.

Docx expects that lists will continue where they left off after an interruption and introduces a new id if a list is starting again. So we keep track of the state of lists and use them to define a "start" attribute, if necessary. Closes #4025

commit3c7a3d378c6fdb026297aee10e4818267a8b86a8 authorJesse Rosenthal <jrosenthal@jhu.edu> dateWed 13 Dec 2017, 15:08 (9 years ago) parentce73dec
1 file changed+22−15
src/Text/Pandoc/Readers/Docx.hs+22−15
src/Text/Pandoc/Readers/Docx.hs+22−15
@@ -121,6 +121,9 @@ data DState = DState { docxAnchorMap :: M.Map String String
121121 , docxMediaBag :: MediaBag
122122 , docxDropCap :: Inlines
123123 , docxWarnings :: [String]
124+ -- keep track of (numId, lvl) values for
125+ -- restarting
126+ , docxListState :: M.Map (String, String) Integer
124127 }
125128
126129instance Default DState where
@@ -128,6 +131,7 @@ instance Default DState where
128131 , docxMediaBag = mempty
129132 , docxDropCap = mempty
130133 , docxWarnings = []
134+ , docxListState = M.empty
131135 }
132136
133137data DEnv = DEnv { docxOptions :: ReaderOptions
@@ -539,22 +543,25 @@ bodyPartToBlocks (Paragraph pPr parparts)
539543 then return mempty
540544 else return $ parStyleToTransform pPr $ para ils'
541545bodyPartToBlocks (ListItem pPr numId lvl (Just levelInfo) parparts) = do
542− let
543− kvs = case levelInfo of
544− (_, fmt, txt, Just start) -> [ ("level", lvl)
545− , ("num-id", numId)
546− , ("format", fmt)
547− , ("text", txt)
548− , ("start", show start)
549− ]
550−
551− (_, fmt, txt, Nothing) -> [ ("level", lvl)
552− , ("num-id", numId)
553− , ("format", fmt)
554− , ("text", txt)
555− ]
546+ -- We check whether this current numId has previously been used,
547+ -- since Docx expects us to pick up where we left off.
548+ listState <- gets docxListState
549+ let startFromState = M.lookup (numId, lvl) listState
550+ (_, fmt,txt, startFromLevelInfo) = levelInfo
551+ start = case startFromState of
552+ Just n -> n + 1
553+ Nothing -> case startFromLevelInfo of
554+ Just n' -> n'
555+ Nothing -> 1
556+ kvs = [ ("level", lvl)
557+ , ("num-id", numId)
558+ , ("format", fmt)
559+ , ("text", txt)
560+ , ("start", show start)
561+ ]
562+ modify $ \st -> st{ docxListState = M.insert (numId, lvl) start listState}
556563 blks <- bodyPartToBlocks (Paragraph pPr parparts)
557− return $ divWith ("", ["list-item"], kvs) blks
564+ return $ divWith ("", ["list-item"], kvs) blks
558565bodyPartToBlocks (ListItem pPr _ _ _ parparts) =
559566 let pPr' = pPr {pStyle = "ListParagraph": pStyle pPr}
560567 in