Docx reader: simplify blockNormalize
Use a function `stripSpaces`, instead of recursion. Makes it a bit easier to read and mantain, and simplify normalizing DefinitionList, which was left out the first time.
This commit is contained in:
parent
7fd48b30e0
commit
3da515bdb0
1 changed files with 8 additions and 10 deletions
|
@ -150,19 +150,17 @@ strNormalize (Str "" : ils) = strNormalize ils
|
|||
strNormalize ((Str s) : (Str s') : l) = strNormalize ((Str (s++s')) : l)
|
||||
strNormalize (il:ils) = il : (strNormalize ils)
|
||||
|
||||
stripSpaces :: [Inline] -> [Inline]
|
||||
stripSpaces ils =
|
||||
reverse $ dropWhile (Space ==) $ reverse $ dropWhile (Space ==) ils
|
||||
|
||||
blockNormalize :: Block -> Block
|
||||
blockNormalize (Plain (Space : ils)) = blockNormalize (Plain ils)
|
||||
blockNormalize (Plain ils) = Plain $ strNormalize ils
|
||||
blockNormalize (Para (Space : ils)) = blockNormalize (Para ils)
|
||||
blockNormalize (Para ils) = Para $ strNormalize ils
|
||||
blockNormalize (Header n attr (Space : ils)) =
|
||||
blockNormalize $ Header n attr ils
|
||||
blockNormalize (Plain ils) = Plain $ strNormalize $ stripSpaces ils
|
||||
blockNormalize (Para ils) = Para $ strNormalize $ stripSpaces ils
|
||||
blockNormalize (Header n attr ils) =
|
||||
Header n attr $ strNormalize ils
|
||||
blockNormalize (Table (Space : ils) align width hdr cells) =
|
||||
blockNormalize $ Table ils align width hdr cells
|
||||
Header n attr $ strNormalize $ stripSpaces ils
|
||||
blockNormalize (Table ils align width hdr cells) =
|
||||
Table (strNormalize ils) align width hdr cells
|
||||
Table (strNormalize $ stripSpaces ils) align width hdr cells
|
||||
blockNormalize blk = blk
|
||||
|
||||
runToInlines :: ReaderOptions -> Docx -> Run -> [Inline]
|
||||
|
|
Loading…
Reference in a new issue