git.iko.soy/typeable/pandoc
on master help sign in
Docx Reader: Remove DummyListItem type

Change 5527465c introduced a `DummyListItem` type in Docx/Parse.hs. In retrospect, this seems like it mixes parsing and iterpretation excessively. What's *really* going on is that we have a list item without and associate level or numeric info. We can decide what to do what that in Docx.hs (treat it like a list paragraph), but the parser shouldn't make that decision. This commit makes what is going on a bit more explicit. `LevelInfo` is now a Maybe value in the `ListItem` type. If it's a Nothing, we treat it as a ListParagraph. If it's a Just, it's a normal list item.

commit07b8a456b1a60e5871a9120eaaeca1dd17e1f6b1 authorJesse Rosenthal <jrosenthal@jhu.edu> dateMon 23 Nov 2015, 11:50 (11 years ago) parenta008e57
2 files changed+7−12
src/Text/Pandoc/Readers/Docx.hs+2−2 src/Text/Pandoc/Readers/Docx/Parse.hs+5−10
src/Text/Pandoc/Readers/Docx.hs+2−2
@@ -486,7 +486,7 @@ bodyPartToBlocks (Paragraph pPr parparts)
486486 return $ case isNull ils' of
487487 True -> mempty
488488 _ -> parStyleToTransform pPr $ para ils'
489−bodyPartToBlocks (ListItem pPr numId lvl levelInfo parparts) = do
489+bodyPartToBlocks (ListItem pPr numId lvl (Just levelInfo) parparts) = do
490490 let
491491 kvs = case levelInfo of
492492 (_, fmt, txt, Just start) -> [ ("level", lvl)
@@ -503,7 +503,7 @@ bodyPartToBlocks (ListItem pPr numId lvl levelInfo parparts) = do
503503 ]
504504 blks <- bodyPartToBlocks (Paragraph pPr parparts)
505505 return $ divWith ("", ["list-item"], kvs) blks
506−bodyPartToBlocks (DummyListItem pPr _ parparts) =
506+bodyPartToBlocks (ListItem pPr _ _ _ parparts) =
507507 let pPr' = pPr {pStyle = "ListParagraph": (pStyle pPr)}
508508 in
509509 bodyPartToBlocks $ Paragraph pPr' parparts
src/Text/Pandoc/Readers/Docx/Parse.hs+5−10
@@ -177,8 +177,7 @@ defaultParagraphStyle = ParagraphStyle { pStyle = []
177177
178178
179179data BodyPart = Paragraph ParagraphStyle [ParPart]
180− | ListItem ParagraphStyle String String Level [ParPart]
181− | DummyListItem ParagraphStyle String [ParPart]
180+ | ListItem ParagraphStyle String String (Maybe Level) [ParPart]
182181 | Tbl String TblGrid TblLook [Row]
183182 | OMathPara [Exp]
184183 deriving Show
@@ -565,9 +564,8 @@ elemToBodyPart ns element
565564 let parstyle = elemToParagraphStyle ns element sty
566565 parparts <- mapD (elemToParPart ns) (elChildren element)
567566 num <- asks envNumbering
568− case lookupLevel numId lvl num of
569− Just levelInfo -> return $ ListItem parstyle numId lvl levelInfo parparts
570− Nothing -> return $ DummyListItem parstyle lvl parparts
567+ let levelInfo = lookupLevel numId lvl num
568+ return $ ListItem parstyle numId lvl levelInfo parparts
571569elemToBodyPart ns element
572570 | isElem ns "w" "p" element = do
573571 sty <- asks envParStyles
@@ -576,11 +574,8 @@ elemToBodyPart ns element
576574 case pNumInfo parstyle of
577575 Just (numId, lvl) -> do
578576 num <- asks envNumbering
579− case lookupLevel numId lvl num of
580− Just levelInfo ->
581− return $ ListItem parstyle numId lvl levelInfo parparts
582− Nothing ->
583− return $ DummyListItem parstyle lvl parparts
577+ let levelInfo = lookupLevel numId lvl num
578+ return $ ListItem parstyle numId lvl levelInfo parparts
584579 Nothing -> return $ Paragraph parstyle parparts
585580elemToBodyPart ns element
586581 | isElem ns "w" "tbl" element = do