git.iko.soy/typeable/pandoc
on master help sign in
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.

commit3da515bdb005cf16589b88d80aa4a8a71760e366 authorJesse Rosenthal <jrosenthal@jhu.edu> dateFri 20 Jun 2014, 10:12 (12 years ago) parent7fd48b3
1 file changed+8−10
src/Text/Pandoc/Readers/Docx.hs+8−10
src/Text/Pandoc/Readers/Docx.hs+8−10
@@ -150,19 +150,17 @@ strNormalize (Str "" : ils) = strNormalize ils
150150strNormalize ((Str s) : (Str s') : l) = strNormalize ((Str (s++s')) : l)
151151strNormalize (il:ils) = il : (strNormalize ils)
152152
153+stripSpaces :: [Inline] -> [Inline]
154+stripSpaces ils =
155+ reverse $ dropWhile (Space ==) $ reverse $ dropWhile (Space ==) ils
156+
153157blockNormalize :: Block -> Block
154−blockNormalize (Plain (Space : ils)) = blockNormalize (Plain ils)
155−blockNormalize (Plain ils) = Plain $ strNormalize ils
156−blockNormalize (Para (Space : ils)) = blockNormalize (Para ils)
157−blockNormalize (Para ils) = Para $ strNormalize ils
158−blockNormalize (Header n attr (Space : ils)) =
159− blockNormalize $ Header n attr ils
158+blockNormalize (Plain ils) = Plain $ strNormalize $ stripSpaces ils
159+blockNormalize (Para ils) = Para $ strNormalize $ stripSpaces ils
160160blockNormalize (Header n attr ils) =
161− Header n attr $ strNormalize ils
162−blockNormalize (Table (Space : ils) align width hdr cells) =
163− blockNormalize $ Table ils align width hdr cells
161+ Header n attr $ strNormalize $ stripSpaces ils
164162blockNormalize (Table ils align width hdr cells) =
165− Table (strNormalize ils) align width hdr cells
163+ Table (strNormalize $ stripSpaces ils) align width hdr cells
166164blockNormalize blk = blk
167165
168166runToInlines :: ReaderOptions -> Docx -> Run -> [Inline]