diff options
author | John MacFarlane <jgm@berkeley.edu> | 2014-06-20 09:15:55 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2014-06-20 09:15:55 -0700 |
commit | d587558859d85d1006606b280f3592343096966e (patch) | |
tree | 81dce0a9467b77900f68682e88e6bfdd268330f3 /src | |
parent | 557b302731411057cf12e62c87d98752f713d5d0 (diff) | |
parent | 2aa5f58c5b82dd5750e1bf5f30e1936d132104ac (diff) | |
download | pandoc-d587558859d85d1006606b280f3592343096966e.tar.gz |
Merge pull request #1355 from jkr/normalizeFixes
Docx reader: Fixes to block Normalization
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Readers/Docx.hs | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/Text/Pandoc/Readers/Docx.hs b/src/Text/Pandoc/Readers/Docx.hs index 9c1d0c5e6..8a8bc46a6 100644 --- a/src/Text/Pandoc/Readers/Docx.hs +++ b/src/Text/Pandoc/Readers/Docx.hs @@ -144,23 +144,29 @@ runElemToString (Tab) = ['\t'] runElemsToString :: [RunElem] -> String runElemsToString = concatMap runElemToString +--- We use this instead of the more general +--- Text.Pandoc.Shared.normalize for reasons of efficiency. For +--- whatever reason, `normalize` makes a run take almost twice as +--- long. (It does more, but this does what we need) strNormalize :: [Inline] -> [Inline] strNormalize [] = [] 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 (Table (Space : ils) align width hdr cells) = - blockNormalize $ Table ils align width hdr cells +blockNormalize (Plain ils) = Plain $ strNormalize $ stripSpaces ils +blockNormalize (Para ils) = Para $ strNormalize $ stripSpaces ils +blockNormalize (Header n attr ils) = + 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 (DefinitionList pairs) = + DefinitionList $ map (\(ils, blklsts) -> (strNormalize (stripSpaces ils), blklsts)) pairs blockNormalize blk = blk runToInlines :: ReaderOptions -> Docx -> Run -> [Inline] |