@@ -79,8 +79,10 @@ import Text.Pandoc.Builder (text, toList)
7979import Text.Pandoc.Generic (bottomUp)
8080import Text.Pandoc.MIME (getMimeType)
8181import Text.Pandoc.UTF8 (toString)
82+import Text.Pandoc.Walk
8283import Text.Pandoc.Readers.Docx.Parse
8384import Text.Pandoc.Readers.Docx.Lists
85+import Text.Pandoc.Readers.Docx.Reducible
8486import Data.Maybe (mapMaybe, isJust, fromJust)
8587import Data.List (delete, isPrefixOf, (\\), intersect)
8688import qualified Data.ByteString as BS
@@ -96,28 +98,65 @@ readDocx opts bytes =
9698 Just docx -> Pandoc nullMeta (docxToBlocks opts docx)
9799 Nothing -> error $ "couldn't parse docx file"
98100
99−runStyleToSpanAttr :: RunStyle -> (String, [String], [(String, String)])
100−runStyleToSpanAttr rPr = ("",
101− mapMaybe id [
102− if isBold rPr then (Just "strong") else Nothing,
103− if isItalic rPr then (Just "emph") else Nothing,
104− if isSmallCaps rPr then (Just "smallcaps") else Nothing,
105− if isStrike rPr then (Just "strike") else Nothing,
106− if isSuperScript rPr then (Just "superscript") else Nothing,
107− if isSubScript rPr then (Just "subscript") else Nothing,
108− rStyle rPr],
109− case underline rPr of
110− Just fmt -> [("underline", fmt)]
111− _ -> []
112− )
113−
114−parStyleToDivAttr :: ParagraphStyle -> (String, [String], [(String, String)])
115−parStyleToDivAttr pPr = ("",
116− pStyle pPr,
117− case indent pPr of
118− Just n -> [("indent", (show n))]
119− Nothing -> []
120− )
101+spansToKeep :: [String]
102+spansToKeep = ["list-item", "Definition", "DefinitionTerm"] ++ codeSpans
103+
104+
105+-- This is empty, but we put it in for future-proofing.
106+divsToKeep :: [String]
107+divsToKeep = []
108+
109+runStyleToContainers :: RunStyle -> [Container Inline]
110+runStyleToContainers rPr =
111+ let formatters = mapMaybe id
112+ [ if isBold rPr then (Just Strong) else Nothing
113+ , if isItalic rPr then (Just Emph) else Nothing
114+ , if isSmallCaps rPr then (Just SmallCaps) else Nothing
115+ , if isStrike rPr then (Just Strikeout) else Nothing
116+ , if isSuperScript rPr then (Just Superscript) else Nothing
117+ , if isSubScript rPr then (Just Subscript) else Nothing
118+ , rStyle rPr >>=
119+ (\s -> if s `elem` spansToKeep then Just s else Nothing) >>=
120+ (\s -> Just $ Span ("", [s], []))
121+ , underline rPr >>= (\f -> Just $ Span ("", [], [("underline", f)]))
122+ ]
123+ in
124+ map Container formatters
125+
126+
127+divAttrToContainers :: [String] -> [(String, String)] -> [Container Block]
128+divAttrToContainers [] [] = []
129+divAttrToContainers (c:cs) _ | isJust (isHeaderClass c) =
130+ let n = fromJust (isHeaderClass c)
131+ in
132+ [(Container $ \blks ->
133+ Header n ("", delete ("Heading" ++ show n) cs, []) (blksToInlines blks))]
134+divAttrToContainers (c:_) _ | c `elem` codeDivs =
135+ [Container $ \blks -> CodeBlock ("", [], []) (concatMap blkToCode blks)]
136+divAttrToContainers (c:cs) kvs | c `elem` listParagraphDivs =
137+ let kvs' = filter (\(k,_) -> k /= "indent") kvs
138+ in
139+ (Container $ Div ("", [c], [])) : (divAttrToContainers cs kvs')
140+divAttrToContainers (c:cs) kvs | c `elem` blockQuoteDivs =
141+ (Container BlockQuote) : (divAttrToContainers (cs \\ blockQuoteDivs) kvs)
142+divAttrToContainers (c:cs) kvs | c `elem` divsToKeep =
143+ (Container $ Div ("", [c], [])) : (divAttrToContainers cs kvs)
144+divAttrToContainers (_:cs) kvs = divAttrToContainers cs kvs
145+divAttrToContainers [] (kv:kvs) | fst kv == "indent" =
146+ (Container BlockQuote) : divAttrToContainers [] kvs
147+divAttrToContainers [] (_:kvs) =
148+ divAttrToContainers [] kvs
149+
150+
151+parStyleToContainers :: ParagraphStyle -> [Container Block]
152+parStyleToContainers pPr =
153+ let classes = pStyle pPr
154+ kvs = case indent pPr of
155+ Just n -> [("indent", show n)]
156+ Nothing -> []
157+ in
158+ divAttrToContainers classes kvs
159+
121160
122161strToInlines :: String -> [Inline]
123162strToInlines = toList . text
@@ -144,103 +183,42 @@ runElemToString (Tab) = ['\t']
144183runElemsToString :: [RunElem] -> String
145184runElemsToString = concatMap runElemToString
146185
147−--- We use this instead of the more general
148−--- Text.Pandoc.Shared.normalize for reasons of efficiency. For
149−--- whatever reason, `normalize` makes a run take almost twice as
150−--- long. (It does more, but this does what we need)
151−inlineNormalize :: [Inline] -> [Inline]
152−inlineNormalize [] = []
153−inlineNormalize (Str "" : ils) = inlineNormalize ils
154−inlineNormalize ((Str s) : (Str s') : l) =
155− inlineNormalize (Str (s++s') : l)
156−inlineNormalize ((Emph ils) : (Emph ils') : l) =
157− inlineNormalize $ (Emph $ inlineNormalize (ils ++ ils')) : l
158−inlineNormalize ((Emph ils) : l) =
159− Emph (inlineNormalize ils) : (inlineNormalize l)
160−inlineNormalize ((Strong ils) : (Strong ils') : l) =
161− inlineNormalize $ (Strong $ inlineNormalize (ils ++ ils')) : l
162−inlineNormalize ((Strong ils) : l) =
163− Strong (inlineNormalize ils) : (inlineNormalize l)
164−inlineNormalize ((Strikeout ils) : (Strikeout ils') : l) =
165− inlineNormalize $ (Strikeout $ inlineNormalize (ils ++ ils')) : l
166−inlineNormalize ((Strikeout ils) : l) =
167− Strikeout (inlineNormalize ils) : (inlineNormalize l)
168−inlineNormalize ((Superscript ils) : (Superscript ils') : l) =
169− inlineNormalize $ (Superscript $ inlineNormalize (ils ++ ils')) : l
170−inlineNormalize ((Superscript ils) : l) =
171− Superscript (inlineNormalize ils) : (inlineNormalize l)
172−inlineNormalize ((Subscript ils) : (Subscript ils') : l) =
173− inlineNormalize $ (Subscript $ inlineNormalize (ils ++ ils')) : l
174−inlineNormalize ((Subscript ils) : l) =
175− Subscript (inlineNormalize ils) : (inlineNormalize l)
176−inlineNormalize ((Space : Space : l)) =
177− inlineNormalize $ (Space : l)
178−inlineNormalize ((Quoted qt ils) : l) =
179− Quoted qt (inlineNormalize ils) : inlineNormalize l
180−inlineNormalize ((Cite cits ils) : l) =
181− let
182− f :: Citation -> Citation
183− f (Citation s pref suff mode num hash) =
184− Citation s (inlineNormalize pref) (inlineNormalize suff) mode num hash
185− in
186− Cite (map f cits) (inlineNormalize ils) : (inlineNormalize l)
187−inlineNormalize ((Link ils s) : l) =
188− Link (inlineNormalize ils) s : (inlineNormalize l)
189−inlineNormalize ((Image ils s) : l) =
190− Image (inlineNormalize ils) s : (inlineNormalize l)
191−inlineNormalize ((Note blks) : l) =
192− Note (map blockNormalize blks) : (inlineNormalize l)
193−inlineNormalize ((Span attr ils) : l) =
194− Span attr (inlineNormalize ils) : (inlineNormalize l)
195−inlineNormalize (il : l) = il : (inlineNormalize l)
196−
197−stripSpaces :: [Inline] -> [Inline]
198−stripSpaces ils =
199− reverse $ dropWhile (Space ==) $ reverse $ dropWhile (Space ==) ils
200−
201−blockNormalize :: Block -> Block
202−blockNormalize (Plain ils) = Plain $ stripSpaces $ inlineNormalize ils
203−blockNormalize (Para ils) = Para $ stripSpaces $ inlineNormalize ils
204−blockNormalize (Header n attr ils) =
205− Header n attr $ stripSpaces $ inlineNormalize ils
206−blockNormalize (Table ils align width hdr cells) =
207− Table (stripSpaces $ inlineNormalize ils) align width hdr cells
208−blockNormalize (DefinitionList pairs) =
209− DefinitionList $ map (\(ils, blklsts) -> (stripSpaces (inlineNormalize ils), (map (map blockNormalize) blklsts))) pairs
210−blockNormalize (BlockQuote blks) = BlockQuote (map blockNormalize blks)
211−blockNormalize (OrderedList attr blkslst) =
212− OrderedList attr $ map (\blks -> map blockNormalize blks) blkslst
213−blockNormalize (BulletList blkslst) =
214− BulletList $ map (\blks -> map blockNormalize blks) blkslst
215−blockNormalize (Div attr blks) = Div attr (map blockNormalize blks)
216−blockNormalize blk = blk
186+
187+inlineCodeContainer :: Container Inline -> Bool
188+inlineCodeContainer (Container f) = case f [] of
189+ Span (_, classes, _) _ -> (not . null) (classes `intersect` codeSpans)
190+ _ -> False
191+inlineCodeContainer _ = False
192+
193+-- blockCodeContainer :: Container Block -> Bool
194+-- blockCodeContainer (Container f) = case f [] of
195+-- Div (ident, classes, kvs) _ -> (not . null) (classes `intersect` codeDivs)
196+-- _ -> False
197+-- blockCodeContainer _ = False
217198
218199runToInlines :: ReaderOptions -> Docx -> Run -> [Inline]
219200runToInlines _ _ (Run rs runElems)
220− | isJust (rStyle rs) && (fromJust (rStyle rs)) `elem` codeSpans =
221− case runStyleToSpanAttr rs == ("", [], []) of
222− True -> [Str (runElemsToString runElems)]
223− False -> [Span (runStyleToSpanAttr rs) [Str (runElemsToString runElems)]]
224− | otherwise = case runStyleToSpanAttr rs == ("", [], []) of
225− True -> concatMap runElemToInlines runElems
226− False -> [Span (runStyleToSpanAttr rs) (concatMap runElemToInlines runElems)]
201+ | any inlineCodeContainer (runStyleToContainers rs) =
202+ rebuild (runStyleToContainers rs) $ [Str $ runElemsToString runElems]
203+ | otherwise =
204+ rebuild (runStyleToContainers rs) (concatMap runElemToInlines runElems)
227205runToInlines opts docx@(Docx _ notes _ _ _ ) (Footnote fnId) =
228206 case (getFootNote fnId notes) of
229207 Just bodyParts ->
230− [Note [Div ("", ["footnote"], []) (map (bodyPartToBlock opts docx) bodyParts)]]
208+ [Note (concatMap (bodyPartToBlocks opts docx) bodyParts)]
231209 Nothing ->
232− [Note [Div ("", ["footnote"], []) []]]
210+ [Note []]
233211runToInlines opts docx@(Docx _ notes _ _ _) (Endnote fnId) =
234212 case (getEndNote fnId notes) of
235213 Just bodyParts ->
236− [Note [Div ("", ["endnote"], []) (map (bodyPartToBlock opts docx) bodyParts)]]
214+ [Note (concatMap (bodyPartToBlocks opts docx) bodyParts)]
237215 Nothing ->
238− [Note [Div ("", ["endnote"], []) []]]
216+ [Note []]
239217
240218parPartToInlines :: ReaderOptions -> Docx -> ParPart -> [Inline]
241219parPartToInlines opts docx (PlainRun r) = runToInlines opts docx r
242−parPartToInlines _ _ (BookMark _ anchor) =
243− [Span (anchor, ["anchor"], []) []]
220+parPartToInlines _ _ (BookMark _ anchor) | anchor `elem` dummyAnchors = []
221+parPartToInlines _ _ (BookMark _ anchor) = [Span (anchor, ["anchor"], []) []]
244222parPartToInlines _ (Docx _ _ _ rels _) (Drawing relid) =
245223 case lookupRelationship relid rels of
246224 Just target -> [Image [] (combine "word" target, "")]
@@ -276,7 +254,6 @@ makeHeaderAnchors h@(Header n (_, classes, kvs) ils) =
276254 _ -> h
277255makeHeaderAnchors blk = blk
278256
279−
280257parPartsToInlines :: ReaderOptions -> Docx -> [ParPart] -> [Inline]
281258parPartsToInlines opts docx parparts =
282259 --
@@ -284,23 +261,32 @@ parPartsToInlines opts docx parparts =
284261 -- not mandatory.
285262 --
286263 (if False -- TODO depend on option
287− then bottomUp (makeImagesSelfContained docx)
264+ then walk (makeImagesSelfContained docx)
288265 else id) $
289− bottomUp spanTrim $
290− bottomUp spanCorrect $
291− bottomUp spanReduce $
292− concatMap (parPartToInlines opts docx) parparts
266+ -- bottomUp spanTrim $
267+ -- bottomUp spanCorrect $
268+ -- bottomUp spanReduce $
269+ reduceList $ concatMap (parPartToInlines opts docx) parparts
293270
294271cellToBlocks :: ReaderOptions -> Docx -> Cell -> [Block]
295−cellToBlocks opts docx (Cell bps) = map (bodyPartToBlock opts docx) bps
272+cellToBlocks opts docx (Cell bps) = concatMap (bodyPartToBlocks opts docx) bps
296273
297274rowToBlocksList :: ReaderOptions -> Docx -> Row -> [[Block]]
298275rowToBlocksList opts docx (Row cells) = map (cellToBlocks opts docx) cells
299276
300−bodyPartToBlock :: ReaderOptions -> Docx -> BodyPart -> Block
301−bodyPartToBlock opts docx (Paragraph pPr parparts) =
302− Div (parStyleToDivAttr pPr) [Para (parPartsToInlines opts docx parparts)]
303−bodyPartToBlock opts docx@(Docx _ _ numbering _ _) (ListItem pPr numId lvl parparts) =
277+bodyPartToBlocks :: ReaderOptions -> Docx -> BodyPart -> [Block]
278+bodyPartToBlocks opts docx (Paragraph pPr parparts) =
279+ case parPartsToInlines opts docx parparts of
280+ [] ->
281+ []
282+ _ ->
283+ let parContents = parPartsToInlines opts docx parparts
284+ trimmedContents = reverse $ dropWhile (Space ==) $ reverse $ dropWhile (Space ==) parContents
285+ in
286+ rebuild
287+ (parStyleToContainers pPr)
288+ [Para trimmedContents]
289+bodyPartToBlocks opts docx@(Docx _ _ numbering _ _) (ListItem pPr numId lvl parparts) =
304290 let
305291 kvs = case lookupLevel numId lvl numbering of
306292 Just (_, fmt, txt, Just start) -> [ ("level", lvl)
@@ -317,12 +303,12 @@ bodyPartToBlock opts docx@(Docx _ _ numbering _ _) (ListItem pPr numId lvl parpa
317303 ]
318304 Nothing -> []
319305 in
320− Div
321− ("", ["list-item"], kvs)
322− [bodyPartToBlock opts docx (Paragraph pPr parparts)]
323−bodyPartToBlock _ _ (Tbl _ _ _ []) =
324− Para []
325−bodyPartToBlock opts docx (Tbl cap _ look (r:rs)) =
306+ [Div
307+ ("", ["list-item"], kvs)
308+ (bodyPartToBlocks opts docx (Paragraph pPr parparts))]
309+bodyPartToBlocks _ _ (Tbl _ _ _ []) =
310+ [Para []]
311+bodyPartToBlocks opts docx (Tbl cap _ look (r:rs)) =
326312 let caption = strToInlines cap
327313 (hdr, rows) = case firstRowFormatting look of
328314 True -> (Just r, rs)
@@ -344,7 +330,8 @@ bodyPartToBlock opts docx (Tbl cap _ look (r:rs)) =
344330 alignments = take size (repeat AlignDefault)
345331 widths = take size (repeat 0) :: [Double]
346332 in
347− Table caption alignments widths hdrCells cells
333+ [Table caption alignments widths hdrCells cells]
334+
348335
349336makeImagesSelfContained :: Docx -> Inline -> Inline
350337makeImagesSelfContained (Docx _ _ _ _ media) i@(Image alt (uri, title)) =
@@ -360,127 +347,19 @@ makeImagesSelfContained _ inline = inline
360347
361348bodyToBlocks :: ReaderOptions -> Docx -> Body -> [Block]
362349bodyToBlocks opts docx (Body bps) =
363− bottomUp removeEmptyPars $
364− map blockNormalize $
365− bottomUp spanRemove $
366− bottomUp divRemove $
367350 map (makeHeaderAnchors) $
368− bottomUp divCorrect $
369− bottomUp divReduce $
370− bottomUp divCorrectPreReduce $
371351 bottomUp blocksToDefinitions $
372352 blocksToBullets $
373− map (bodyPartToBlock opts docx) bps
353+ concatMap (bodyPartToBlocks opts docx) bps
374354
375355docxToBlocks :: ReaderOptions -> Docx -> [Block]
376356docxToBlocks opts d@(Docx (Document _ body) _ _ _ _) = bodyToBlocks opts d body
377357
378−spanReduce :: [Inline] -> [Inline]
379−spanReduce [] = []
380−spanReduce ((Span (id1, classes1, kvs1) ils1) : ils)
381− | (id1, classes1, kvs1) == ("", [], []) = ils1 ++ (spanReduce ils)
382−spanReduce (s1@(Span (id1, classes1, kvs1) ils1) :
383− s2@(Span (id2, classes2, kvs2) ils2) :
384− ils) =
385− let classes' = classes1 `intersect` classes2
386− kvs' = kvs1 `intersect` kvs2
387− classes1' = classes1 \\ classes'
388− kvs1' = kvs1 \\ kvs'
389− classes2' = classes2 \\ classes'
390− kvs2' = kvs2 \\ kvs'
391− in
392− case null classes' && null kvs' of
393− True -> s1 : (spanReduce (s2 : ils))
394− False -> let attr' = ("", classes', kvs')
395− attr1' = (id1, classes1', kvs1')
396− attr2' = (id2, classes2', kvs2')
397− in
398− spanReduce (Span attr' [(Span attr1' ils1), (Span attr2' ils2)] :
399− ils)
400−spanReduce (il:ils) = il : (spanReduce ils)
401358
402359ilToCode :: Inline -> String
403360ilToCode (Str s) = s
404361ilToCode _ = ""
405362
406−spanRemove' :: Inline -> [Inline]
407−spanRemove' s@(Span (ident, classes, _) [])
408− -- "_GoBack" is automatically inserted. We don't want to keep it.
409− | classes == ["anchor"] && not (ident `elem` dummyAnchors) = [s]
410−spanRemove' (Span (_, _, kvs) ils) =
411− case lookup "underline" kvs of
412− Just val -> [Span ("", [], [("underline", val)]) ils]
413− Nothing -> ils
414−spanRemove' il = [il]
415−
416−spanRemove :: [Inline] -> [Inline]
417−spanRemove = concatMap spanRemove'
418−
419−spanTrim' :: Inline -> [Inline]
420−spanTrim' il@(Span _ []) = [il]
421−spanTrim' il@(Span attr (il':[]))
422− | il' == Space = [Span attr [], Space]
423− | otherwise = [il]
424−spanTrim' (Span attr ils)
425− | head ils == Space && last ils == Space =
426− [Space, Span attr (init $ tail ils), Space]
427− | head ils == Space = [Space, Span attr (tail ils)]
428− | last ils == Space = [Span attr (init ils), Space]
429−spanTrim' il = [il]
430−
431−spanTrim :: [Inline] -> [Inline]
432−spanTrim = concatMap spanTrim'
433−
434−spanCorrect' :: Inline -> [Inline]
435−spanCorrect' (Span ("", [], []) ils) = ils
436−spanCorrect' (Span (ident, classes, kvs) ils)
437− | "emph" `elem` classes =
438− [Emph $ spanCorrect' $ Span (ident, (delete "emph" classes), kvs) ils]
439− | "strong" `elem` classes =
440− [Strong $ spanCorrect' $ Span (ident, (delete "strong" classes), kvs) ils]
441− | "smallcaps" `elem` classes =
442− [SmallCaps $ spanCorrect' $ Span (ident, (delete "smallcaps" classes), kvs) ils]
443− | "strike" `elem` classes =
444− [Strikeout $ spanCorrect' $ Span (ident, (delete "strike" classes), kvs) ils]
445− | "superscript" `elem` classes =
446− [Superscript $ spanCorrect' $ Span (ident, (delete "superscript" classes), kvs) ils]
447− | "subscript" `elem` classes =
448− [Subscript $ spanCorrect' $ Span (ident, (delete "subscript" classes), kvs) ils]
449− | (not . null) (codeSpans `intersect` classes) =
450− [Code (ident, (classes \\ codeSpans), kvs) (init $ unlines $ map ilToCode ils)]
451− | otherwise =
452− [Span (ident, classes, kvs) ils]
453−spanCorrect' il = [il]
454−
455−spanCorrect :: [Inline] -> [Inline]
456−spanCorrect = concatMap spanCorrect'
457−
458−removeEmptyPars :: [Block] -> [Block]
459−removeEmptyPars blks = filter (\b -> b /= (Para [])) blks
460−
461−divReduce :: [Block] -> [Block]
462−divReduce [] = []
463−divReduce ((Div (id1, classes1, kvs1) blks1) : blks)
464− | (id1, classes1, kvs1) == ("", [], []) = blks1 ++ (divReduce blks)
465−divReduce (d1@(Div (id1, classes1, kvs1) blks1) :
466− d2@(Div (id2, classes2, kvs2) blks2) :
467− blks) =
468− let classes' = classes1 `intersect` classes2
469− kvs' = kvs1 `intersect` kvs2
470− classes1' = classes1 \\ classes'
471− kvs1' = kvs1 \\ kvs'
472− classes2' = classes2 \\ classes'
473− kvs2' = kvs2 \\ kvs'
474− in
475− case null classes' && null kvs' of
476− True -> d1 : (divReduce (d2 : blks))
477− False -> let attr' = ("", classes', kvs')
478− attr1' = (id1, classes1', kvs1')
479− attr2' = (id2, classes2', kvs2')
480− in
481− divReduce (Div attr' [(Div attr1' blks1), (Div attr2' blks2)] :
482− blks)
483−divReduce (blk:blks) = blk : (divReduce blks)
484363
485364isHeaderClass :: String -> Maybe Int
486365isHeaderClass s | "Heading" `isPrefixOf` s =
@@ -490,27 +369,12 @@ isHeaderClass s | "Heading" `isPrefixOf` s =
490369 _ -> Nothing
491370isHeaderClass _ = Nothing
492371
493−findHeaderClass :: [String] -> Maybe Int
494−findHeaderClass ss = case mapMaybe id $ map isHeaderClass ss of
495− [] -> Nothing
496− n : _ -> Just n
497372
498373blksToInlines :: [Block] -> [Inline]
499374blksToInlines (Para ils : _) = ils
500375blksToInlines (Plain ils : _) = ils
501376blksToInlines _ = []
502377
503−divCorrectPreReduce' :: Block -> [Block]
504−divCorrectPreReduce' (Div (ident, classes, kvs) blks)
505− | isJust $ findHeaderClass classes =
506− let n = fromJust $ findHeaderClass classes
507− in
508− [Header n (ident, delete ("Heading" ++ (show n)) classes, kvs) (blksToInlines blks)]
509− | otherwise = [Div (ident, classes, kvs) blks]
510−divCorrectPreReduce' blk = [blk]
511−
512−divCorrectPreReduce :: [Block] -> [Block]
513−divCorrectPreReduce = concatMap divCorrectPreReduce'
514378
515379blkToCode :: Block -> String
516380blkToCode (Para []) = ""
@@ -520,29 +384,3 @@ blkToCode (Para ((Span (_, classes, _) ils'): ils))
520384 (init $ unlines $ map ilToCode ils') ++ (blkToCode (Para ils))
521385blkToCode _ = ""
522386
523−divRemove' :: Block -> [Block]
524−divRemove' (Div (_, _, kvs) blks) =
525− case lookup "indent" kvs of
526− Just val -> [Div ("", [], [("indent", val)]) blks]
527− Nothing -> blks
528−divRemove' blk = [blk]
529−
530−divRemove :: [Block] -> [Block]
531−divRemove = concatMap divRemove'
532−
533−divCorrect' :: Block -> [Block]
534−divCorrect' b@(Div (ident, classes, kvs) blks)
535− | (not . null) (blockQuoteDivs `intersect` classes) =
536− [BlockQuote [Div (ident, classes \\ blockQuoteDivs, kvs) blks]]
537− | (not . null) (codeDivs `intersect` classes) =
538− [CodeBlock (ident, (classes \\ codeDivs), kvs) (init $ unlines $ map blkToCode blks)]
539− | otherwise =
540− case lookup "indent" kvs of
541− Just "0" -> [Div (ident, classes, filter (\kv -> fst kv /= "indent") kvs) blks]
542− Just _ ->
543− [BlockQuote [Div (ident, classes, filter (\kv -> fst kv /= "indent") kvs) blks]]
544− Nothing -> [b]
545−divCorrect' blk = [blk]
546−
547−divCorrect :: [Block] -> [Block]
548−divCorrect = concatMap divCorrect'