Docx reader: more efficient trimSps.

Replacing trimLineBreaks.  This does the work of
normalizeSpaces as well, so we avoid the need for that
function here.

See #1530.
This commit is contained in:
John MacFarlane 2017-03-10 20:33:30 +01:00
parent 9862d7c359
commit a197dc9d3f

View file

@ -83,7 +83,7 @@ import Data.Default (Default)
import Data.List (delete, intersect) import Data.List (delete, intersect)
import qualified Data.Map as M import qualified Data.Map as M
import Data.Sequence (ViewL (..), viewl) import Data.Sequence (ViewL (..), viewl)
import qualified Data.Sequence as Seq (null) import qualified Data.Sequence as Seq
import qualified Data.Set as Set import qualified Data.Set as Set
import Text.Pandoc.Builder import Text.Pandoc.Builder
-- import Text.Pandoc.Definition -- import Text.Pandoc.Definition
@ -476,12 +476,13 @@ rowToBlocksList (Row cells) = do
blksList <- mapM cellToBlocks cells blksList <- mapM cellToBlocks cells
return $ map singleParaToPlain blksList return $ map singleParaToPlain blksList
trimLineBreaks :: [Inline] -> [Inline] -- like trimInlines, but also take out linebreaks
trimLineBreaks [] = [] trimSps :: Inlines -> Inlines
trimLineBreaks (LineBreak : ils) = trimLineBreaks ils trimSps (Many ils) = Many $ Seq.dropWhileL isSp $ Seq.dropWhileR isSp $ ils
trimLineBreaks ils where isSp Space = True
| (LineBreak : ils') <- reverse ils = trimLineBreaks (reverse ils') isSp SoftBreak = True
trimLineBreaks ils = ils isSp LineBreak = True
isSp _ = False
parStyleToTransform :: ParagraphStyle -> (Blocks -> Blocks) parStyleToTransform :: ParagraphStyle -> (Blocks -> Blocks)
parStyleToTransform pPr parStyleToTransform pPr
@ -534,8 +535,7 @@ bodyPartToBlocks (Paragraph pPr parparts)
makeHeaderAnchor $ makeHeaderAnchor $
headerWith ("", delete style (pStyle pPr), []) n ils headerWith ("", delete style (pStyle pPr), []) n ils
| otherwise = do | otherwise = do
ils <- smushInlines <$> mapM parPartToInlines parparts >>= ils <- (trimSps . smushInlines) <$> mapM parPartToInlines parparts
(return . fromList . trimLineBreaks . normalizeSpaces . toList)
dropIls <- gets docxDropCap dropIls <- gets docxDropCap
let ils' = dropIls <> ils let ils' = dropIls <> ils
if dropCap pPr if dropCap pPr