git.iko.soy/typeable/pandoc
on master help sign in
Docx reader: pass definition test.
5ae6b8cJesse Rosenthal
src/Text/Pandoc/Readers/Docx.hs+13−8
@@ -99,12 +99,12 @@ readDocx opts bytes =
99 Nothing -> error $ "couldn't parse docx file"
99 Nothing -> error $ "couldn't parse docx file"
100
100
101spansToKeep :: [String]
101spansToKeep :: [String]
102−spansToKeep = ["list-item", "Definition", "DefinitionTerm"]
102+spansToKeep = []
103
103
104
104
105-- This is empty, but we put it in for future-proofing.
105-- This is empty, but we put it in for future-proofing.
106divsToKeep :: [String]
106divsToKeep :: [String]
107−divsToKeep = []
107+divsToKeep = ["list-item", "Definition", "DefinitionTerm"]
108
108
109runStyleToContainers :: RunStyle -> [Container Inline]
109runStyleToContainers :: RunStyle -> [Container Inline]
110runStyleToContainers rPr =
110runStyleToContainers rPr =
@@ -139,18 +139,18 @@ divAttrToContainers (c:cs) _ | isJust (isHeaderClass c) =
139 in
139 in
140 [(Container $ \blks ->
140 [(Container $ \blks ->
141 Header n ("", delete ("Heading" ++ show n) cs, []) (blksToInlines blks))]
141 Header n ("", delete ("Heading" ++ show n) cs, []) (blksToInlines blks))]
142−divAttrToContainers (c:_) _ | c `elem` codeDivs =
142+divAttrToContainers (c:cs) kvs | c `elem` divsToKeep =
143+ (Container $ Div ("", [c], [])) : (divAttrToContainers cs kvs)
144+divAttrToContainers (c:cs) kvs | c `elem` codeDivs =
143 -- This is a bit of a cludge. We make the codeblock from the raw
145 -- This is a bit of a cludge. We make the codeblock from the raw
144 -- parparts in bodyPartToBlocks. But we need something to match against.
146 -- parparts in bodyPartToBlocks. But we need something to match against.
145− [Container $ \_ -> CodeBlock ("", [], []) ""]
147+ (Container $ \_ -> CodeBlock ("", [], []) "") : (divAttrToContainers cs kvs)
146divAttrToContainers (c:cs) kvs | c `elem` listParagraphDivs =
148divAttrToContainers (c:cs) kvs | c `elem` listParagraphDivs =
147 let kvs' = filter (\(k,_) -> k /= "indent") kvs
149 let kvs' = filter (\(k,_) -> k /= "indent") kvs
148 in
150 in
149 (Container $ Div ("", [c], [])) : (divAttrToContainers cs kvs')
151 (Container $ Div ("", [c], [])) : (divAttrToContainers cs kvs')
150divAttrToContainers (c:cs) kvs | c `elem` blockQuoteDivs =
152divAttrToContainers (c:cs) kvs | c `elem` blockQuoteDivs =
151 (Container BlockQuote) : (divAttrToContainers (cs \\ blockQuoteDivs) kvs)
153 (Container BlockQuote) : (divAttrToContainers (cs \\ blockQuoteDivs) kvs)
152−divAttrToContainers (c:cs) kvs | c `elem` divsToKeep =
153− (Container $ Div ("", [c], [])) : (divAttrToContainers cs kvs)
154divAttrToContainers (_:cs) kvs = divAttrToContainers cs kvs
154divAttrToContainers (_:cs) kvs = divAttrToContainers cs kvs
155divAttrToContainers [] (kv:kvs) | fst kv == "indent" =
155divAttrToContainers [] (kv:kvs) | fst kv == "indent" =
156 (Container BlockQuote) : divAttrToContainers [] kvs
156 (Container BlockQuote) : divAttrToContainers [] kvs
@@ -298,7 +298,12 @@ blockCodeContainer _ = False
298bodyPartToBlocks :: ReaderOptions -> Docx -> BodyPart -> [Block]
298bodyPartToBlocks :: ReaderOptions -> Docx -> BodyPart -> [Block]
299bodyPartToBlocks _ _ (Paragraph pPr parparts)
299bodyPartToBlocks _ _ (Paragraph pPr parparts)
300 | any blockCodeContainer (parStyleToContainers pPr) =
300 | any blockCodeContainer (parStyleToContainers pPr) =
301+ let
302+ otherConts = filter (not . blockCodeContainer) (parStyleToContainers pPr)
303+ in
304+ rebuild
305+ otherConts
301− [CodeBlock ("", [], []) (concatMap parPartToString parparts)]
306+ [CodeBlock ("", [], []) (concatMap parPartToString parparts)]
302bodyPartToBlocks opts docx (Paragraph pPr parparts) =
307bodyPartToBlocks opts docx (Paragraph pPr parparts) =
303 case parPartsToInlines opts docx parparts of
308 case parPartsToInlines opts docx parparts of
304 [] ->
309 [] ->
@@ -372,7 +377,7 @@ makeImagesSelfContained _ inline = inline
372bodyToBlocks :: ReaderOptions -> Docx -> Body -> [Block]
377bodyToBlocks :: ReaderOptions -> Docx -> Body -> [Block]
373bodyToBlocks opts docx (Body bps) =
378bodyToBlocks opts docx (Body bps) =
374 map (makeHeaderAnchors) $
379 map (makeHeaderAnchors) $
375− bottomUp blocksToDefinitions $
380+ blocksToDefinitions $
376 blocksToBullets $
381 blocksToBullets $
377 concatMap (bodyPartToBlocks opts docx) bps
382 concatMap (bodyPartToBlocks opts docx) bps
378
383