git.iko.soy/typeable/pandoc
on master help sign in
Docx reader: Handle dummy list items.

These come up when people create a list item and then delete the bullet. It doesn't refer to any real list item, and we used to ignore it. We handle it with a DummyListItem type, which, in Docx.hs, is turned into a normal paragraph with a "ListParagraph" class. If it follow another list item, it is folded as another paragraph into that item. If it doesn't, it's just its own (usually indented, and therefore block-quoted) paragraph.

commit5527465c778736e91e88fae414ea26558b966724 authorJesse Rosenthal <jrosenthal@jhu.edu> dateWed 18 Nov 2015, 13:02 (11 years ago) parent1f2c373
2 files changed+15−6
src/Text/Pandoc/Readers/Docx.hs+4 src/Text/Pandoc/Readers/Docx/Parse.hs+11−6
src/Text/Pandoc/Readers/Docx.hs+4
@@ -503,6 +503,10 @@ 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) =
507+ let pPr' = pPr {pStyle = "ListParagraph": (pStyle pPr)}
508+ in
509+ bodyPartToBlocks $ Paragraph pPr' parparts
506510bodyPartToBlocks (Tbl _ _ _ []) =
507511 return $ para mempty
508512bodyPartToBlocks (Tbl cap _ look (r:rs)) = do
src/Text/Pandoc/Readers/Docx/Parse.hs+11−6
@@ -144,9 +144,6 @@ type Level = (String, String, String, Maybe Integer)
144144data DocumentLocation = InDocument | InFootnote | InEndnote
145145 deriving (Eq,Show)
146146
147−-- data RelationshipType = DocumentRel | FootnoteRel | EndnoteRel
148−-- deriving Show
149−
150147data Relationship = Relationship DocumentLocation RelId Target
151148 deriving Show
152149
@@ -181,6 +178,7 @@ defaultParagraphStyle = ParagraphStyle { pStyle = []
181178
182179data BodyPart = Paragraph ParagraphStyle [ParPart]
183180 | ListItem ParagraphStyle String String Level [ParPart]
181+ | DummyListItem ParagraphStyle String [ParPart]
184182 | Tbl String TblGrid TblLook [Row]
185183 | OMathPara [Exp]
186184 deriving Show
@@ -245,7 +243,6 @@ defaultRunStyle = RunStyle { isBold = Nothing
245243 , rUnderline = Nothing
246244 , rStyle = Nothing}
247245
248−
249246type Target = String
250247type Anchor = String
251248type URL = String
@@ -411,6 +408,13 @@ archiveToMedia :: Archive -> Media
411408archiveToMedia zf =
412409 mapMaybe (getMediaPair zf) (filter filePathIsMedia (filesInArchive zf))
413410
411+-- lookupLevel :: String -> String -> Numbering -> Maybe Level
412+-- lookupLevel numId ilvl (Numbering _ numbs absNumbs) = do
413+-- absNumId <- lookup numId $ map (\(Numb nid absnumid) -> (nid, absnumid)) numbs
414+-- lvls <- lookup absNumId $ map (\(AbstractNumb aid ls) -> (aid, ls)) absNumbs
415+-- lvl <- lookup ilvl $ map (\l@(i, _, _, _) -> (i, l)) lvls
416+-- return lvl
417+
414418lookupLevel :: String -> String -> Numbering -> Maybe Level
415419lookupLevel numId ilvl (Numbering _ numbs absNumbs) = do
416420 absNumId <- lookup numId $ map (\(Numb nid absnumid) -> (nid, absnumid)) numbs
@@ -418,6 +422,7 @@ lookupLevel numId ilvl (Numbering _ numbs absNumbs) = do
418422 lvl <- lookup ilvl $ map (\l@(i, _, _, _) -> (i, l)) lvls
419423 return lvl
420424
425+
421426numElemToNum :: NameSpaces -> Element -> Maybe Numb
422427numElemToNum ns element |
423428 qName (elName element) == "num" &&
@@ -569,7 +574,7 @@ elemToBodyPart ns element
569574 num <- asks envNumbering
570575 case lookupLevel numId lvl num of
571576 Just levelInfo -> return $ ListItem parstyle numId lvl levelInfo parparts
572− Nothing -> throwError WrongElem
577+ Nothing -> return $ DummyListItem parstyle lvl parparts
573578elemToBodyPart ns element
574579 | isElem ns "w" "p" element = do
575580 sty <- asks envParStyles
@@ -582,7 +587,7 @@ elemToBodyPart ns element
582587 Just levelInfo ->
583588 return $ ListItem parstyle numId lvl levelInfo parparts
584589 Nothing ->
585− throwError WrongElem
590+ return $ DummyListItem parstyle lvl parparts
586591 Nothing -> return $ Paragraph parstyle parparts
587592elemToBodyPart ns element
588593 | isElem ns "w" "tbl" element = do