git.iko.soy/typeable/pandoc
on master help sign in
Move some of the clean-up logic into List module.

This will allow us to get rid of more general functions we no longer need in the main reader.

commit94d0fb15382a4855938c540c9e521642bccc00e3 authorJesse Rosenthal <jrosenthal@jhu.edu> dateMon 23 Jun 2014, 15:27 (12 years ago) parentef5fad2
1 file changed+22−3
src/Text/Pandoc/Readers/Docx/Lists.hs+22−3
src/Text/Pandoc/Readers/Docx/Lists.hs+22−3
@@ -29,9 +29,12 @@ Functions for converting flat docx paragraphs into nested lists.
2929-}
3030
3131module Text.Pandoc.Readers.Docx.Lists ( blocksToBullets
32− , blocksToDefinitions) where
32+ , blocksToDefinitions
33+ , listParagraphDivs
34+ ) where
3335
3436import Text.Pandoc.JSON
37+import Text.Pandoc.Generic (bottomUp)
3538import Text.Pandoc.Shared (trim)
3639import Control.Monad
3740import Data.List
@@ -159,10 +162,9 @@ flatToBullets elems = flatToBullets' (-1) elems
159162
160163blocksToBullets :: [Block] -> [Block]
161164blocksToBullets blks =
162− -- bottomUp removeListItemDivs $
165+ bottomUp removeListDivs $
163166 flatToBullets $ (handleListParagraphs blks)
164167
165−
166168plainParaInlines :: Block -> [Inline]
167169plainParaInlines (Plain ils) = ils
168170plainParaInlines (Para ils) = ils
@@ -199,6 +201,23 @@ blocksToDefinitions' [] acc (b:blks) =
199201blocksToDefinitions' defAcc acc (b:blks) =
200202 blocksToDefinitions' [] (b : (DefinitionList (reverse defAcc)) : acc) blks
201203
204+removeListDivs' :: Block -> [Block]
205+removeListDivs' (Div (ident, classes, kvs) blks)
206+ | "list-item" `elem` classes =
207+ case delete "list-item" classes of
208+ [] -> blks
209+ classes' -> [Div (ident, classes', kvs) $ blks]
210+removeListDivs' (Div (ident, classes, kvs) blks)
211+ | not $ null $ listParagraphDivs `intersect` classes =
212+ case classes \\ listParagraphDivs of
213+ [] -> blks
214+ classes' -> [Div (ident, classes', kvs) blks]
215+removeListDivs' blk = [blk]
216+
217+removeListDivs :: [Block] -> [Block]
218+removeListDivs = concatMap removeListDivs'
219+
220+
202221
203222blocksToDefinitions :: [Block] -> [Block]
204223blocksToDefinitions = blocksToDefinitions' [] []