diff options
author | Jesse Rosenthal <jrosenthal@jhu.edu> | 2014-06-20 10:12:28 -0400 |
---|---|---|
committer | Jesse Rosenthal <jrosenthal@jhu.edu> | 2014-06-20 10:12:28 -0400 |
commit | 3da515bdb005cf16589b88d80aa4a8a71760e366 (patch) | |
tree | c2b8ca61cdc19ab01725fb5157aff15497b96c3c /src/Text/Pandoc/Readers | |
parent | 7fd48b30e0a6e1e3c02a2b66c76118d10c02636f (diff) | |
download | pandoc-3da515bdb005cf16589b88d80aa4a8a71760e366.tar.gz |
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.
Diffstat (limited to 'src/Text/Pandoc/Readers')
-rw-r--r-- | src/Text/Pandoc/Readers/Docx.hs | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/Text/Pandoc/Readers/Docx.hs b/src/Text/Pandoc/Readers/Docx.hs index 84d50a396..08afc94e6 100644 --- a/src/Text/Pandoc/Readers/Docx.hs +++ b/src/Text/Pandoc/Readers/Docx.hs @@ -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] |