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.
This commit is contained in:
parent
1f2c37392c
commit
5527465c77
2 changed files with 15 additions and 6 deletions
|
@ -503,6 +503,10 @@ bodyPartToBlocks (ListItem pPr numId lvl levelInfo parparts) = do
|
|||
]
|
||||
blks <- bodyPartToBlocks (Paragraph pPr parparts)
|
||||
return $ divWith ("", ["list-item"], kvs) blks
|
||||
bodyPartToBlocks (DummyListItem pPr _ parparts) =
|
||||
let pPr' = pPr {pStyle = "ListParagraph": (pStyle pPr)}
|
||||
in
|
||||
bodyPartToBlocks $ Paragraph pPr' parparts
|
||||
bodyPartToBlocks (Tbl _ _ _ []) =
|
||||
return $ para mempty
|
||||
bodyPartToBlocks (Tbl cap _ look (r:rs)) = do
|
||||
|
|
|
@ -144,9 +144,6 @@ type Level = (String, String, String, Maybe Integer)
|
|||
data DocumentLocation = InDocument | InFootnote | InEndnote
|
||||
deriving (Eq,Show)
|
||||
|
||||
-- data RelationshipType = DocumentRel | FootnoteRel | EndnoteRel
|
||||
-- deriving Show
|
||||
|
||||
data Relationship = Relationship DocumentLocation RelId Target
|
||||
deriving Show
|
||||
|
||||
|
@ -181,6 +178,7 @@ defaultParagraphStyle = ParagraphStyle { pStyle = []
|
|||
|
||||
data BodyPart = Paragraph ParagraphStyle [ParPart]
|
||||
| ListItem ParagraphStyle String String Level [ParPart]
|
||||
| DummyListItem ParagraphStyle String [ParPart]
|
||||
| Tbl String TblGrid TblLook [Row]
|
||||
| OMathPara [Exp]
|
||||
deriving Show
|
||||
|
@ -245,7 +243,6 @@ defaultRunStyle = RunStyle { isBold = Nothing
|
|||
, rUnderline = Nothing
|
||||
, rStyle = Nothing}
|
||||
|
||||
|
||||
type Target = String
|
||||
type Anchor = String
|
||||
type URL = String
|
||||
|
@ -411,6 +408,13 @@ archiveToMedia :: Archive -> Media
|
|||
archiveToMedia zf =
|
||||
mapMaybe (getMediaPair zf) (filter filePathIsMedia (filesInArchive zf))
|
||||
|
||||
-- lookupLevel :: String -> String -> Numbering -> Maybe Level
|
||||
-- lookupLevel numId ilvl (Numbering _ numbs absNumbs) = do
|
||||
-- absNumId <- lookup numId $ map (\(Numb nid absnumid) -> (nid, absnumid)) numbs
|
||||
-- lvls <- lookup absNumId $ map (\(AbstractNumb aid ls) -> (aid, ls)) absNumbs
|
||||
-- lvl <- lookup ilvl $ map (\l@(i, _, _, _) -> (i, l)) lvls
|
||||
-- return lvl
|
||||
|
||||
lookupLevel :: String -> String -> Numbering -> Maybe Level
|
||||
lookupLevel numId ilvl (Numbering _ numbs absNumbs) = do
|
||||
absNumId <- lookup numId $ map (\(Numb nid absnumid) -> (nid, absnumid)) numbs
|
||||
|
@ -418,6 +422,7 @@ lookupLevel numId ilvl (Numbering _ numbs absNumbs) = do
|
|||
lvl <- lookup ilvl $ map (\l@(i, _, _, _) -> (i, l)) lvls
|
||||
return lvl
|
||||
|
||||
|
||||
numElemToNum :: NameSpaces -> Element -> Maybe Numb
|
||||
numElemToNum ns element |
|
||||
qName (elName element) == "num" &&
|
||||
|
@ -569,7 +574,7 @@ elemToBodyPart ns element
|
|||
num <- asks envNumbering
|
||||
case lookupLevel numId lvl num of
|
||||
Just levelInfo -> return $ ListItem parstyle numId lvl levelInfo parparts
|
||||
Nothing -> throwError WrongElem
|
||||
Nothing -> return $ DummyListItem parstyle lvl parparts
|
||||
elemToBodyPart ns element
|
||||
| isElem ns "w" "p" element = do
|
||||
sty <- asks envParStyles
|
||||
|
@ -582,7 +587,7 @@ elemToBodyPart ns element
|
|||
Just levelInfo ->
|
||||
return $ ListItem parstyle numId lvl levelInfo parparts
|
||||
Nothing ->
|
||||
throwError WrongElem
|
||||
return $ DummyListItem parstyle lvl parparts
|
||||
Nothing -> return $ Paragraph parstyle parparts
|
||||
elemToBodyPart ns element
|
||||
| isElem ns "w" "tbl" element = do
|
||||
|
|
Loading…
Add table
Reference in a new issue