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.
This commit is contained in:
Jesse Rosenthal 2014-06-23 15:27:01 -04:00
parent ef5fad2698
commit 94d0fb1538

View file

@ -29,9 +29,12 @@ Functions for converting flat docx paragraphs into nested lists.
-} -}
module Text.Pandoc.Readers.Docx.Lists ( blocksToBullets module Text.Pandoc.Readers.Docx.Lists ( blocksToBullets
, blocksToDefinitions) where , blocksToDefinitions
, listParagraphDivs
) where
import Text.Pandoc.JSON import Text.Pandoc.JSON
import Text.Pandoc.Generic (bottomUp)
import Text.Pandoc.Shared (trim) import Text.Pandoc.Shared (trim)
import Control.Monad import Control.Monad
import Data.List import Data.List
@ -159,10 +162,9 @@ flatToBullets elems = flatToBullets' (-1) elems
blocksToBullets :: [Block] -> [Block] blocksToBullets :: [Block] -> [Block]
blocksToBullets blks = blocksToBullets blks =
-- bottomUp removeListItemDivs $ bottomUp removeListDivs $
flatToBullets $ (handleListParagraphs blks) flatToBullets $ (handleListParagraphs blks)
plainParaInlines :: Block -> [Inline] plainParaInlines :: Block -> [Inline]
plainParaInlines (Plain ils) = ils plainParaInlines (Plain ils) = ils
plainParaInlines (Para ils) = ils plainParaInlines (Para ils) = ils
@ -199,6 +201,23 @@ blocksToDefinitions' [] acc (b:blks) =
blocksToDefinitions' defAcc acc (b:blks) = blocksToDefinitions' defAcc acc (b:blks) =
blocksToDefinitions' [] (b : (DefinitionList (reverse defAcc)) : acc) blks blocksToDefinitions' [] (b : (DefinitionList (reverse defAcc)) : acc) blks
removeListDivs' :: Block -> [Block]
removeListDivs' (Div (ident, classes, kvs) blks)
| "list-item" `elem` classes =
case delete "list-item" classes of
[] -> blks
classes' -> [Div (ident, classes', kvs) $ blks]
removeListDivs' (Div (ident, classes, kvs) blks)
| not $ null $ listParagraphDivs `intersect` classes =
case classes \\ listParagraphDivs of
[] -> blks
classes' -> [Div (ident, classes', kvs) blks]
removeListDivs' blk = [blk]
removeListDivs :: [Block] -> [Block]
removeListDivs = concatMap removeListDivs'
blocksToDefinitions :: [Block] -> [Block] blocksToDefinitions :: [Block] -> [Block]
blocksToDefinitions = blocksToDefinitions' [] [] blocksToDefinitions = blocksToDefinitions' [] []