diff options
author | John MacFarlane <jgm@berkeley.edu> | 2017-03-10 20:33:30 +0100 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2017-03-10 20:34:25 +0100 |
commit | a197dc9d3fa578d223ab07884906351cced646c9 (patch) | |
tree | 355efa34e71bed81e4fe7f59a90a106111b6bb49 /src/Text | |
parent | 9862d7c359ce4f9e5f89c4ee5131e0f051c134d2 (diff) | |
download | pandoc-a197dc9d3fa578d223ab07884906351cced646c9.tar.gz |
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.
Diffstat (limited to 'src/Text')
-rw-r--r-- | src/Text/Pandoc/Readers/Docx.hs | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/Text/Pandoc/Readers/Docx.hs b/src/Text/Pandoc/Readers/Docx.hs index 108055b42..a5efdae57 100644 --- a/src/Text/Pandoc/Readers/Docx.hs +++ b/src/Text/Pandoc/Readers/Docx.hs @@ -83,7 +83,7 @@ import Data.Default (Default) import Data.List (delete, intersect) import qualified Data.Map as M 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 Text.Pandoc.Builder -- import Text.Pandoc.Definition @@ -476,12 +476,13 @@ rowToBlocksList (Row cells) = do blksList <- mapM cellToBlocks cells return $ map singleParaToPlain blksList -trimLineBreaks :: [Inline] -> [Inline] -trimLineBreaks [] = [] -trimLineBreaks (LineBreak : ils) = trimLineBreaks ils -trimLineBreaks ils - | (LineBreak : ils') <- reverse ils = trimLineBreaks (reverse ils') -trimLineBreaks ils = ils +-- like trimInlines, but also take out linebreaks +trimSps :: Inlines -> Inlines +trimSps (Many ils) = Many $ Seq.dropWhileL isSp $ Seq.dropWhileR isSp $ ils + where isSp Space = True + isSp SoftBreak = True + isSp LineBreak = True + isSp _ = False parStyleToTransform :: ParagraphStyle -> (Blocks -> Blocks) parStyleToTransform pPr @@ -534,8 +535,7 @@ bodyPartToBlocks (Paragraph pPr parparts) makeHeaderAnchor $ headerWith ("", delete style (pStyle pPr), []) n ils | otherwise = do - ils <- smushInlines <$> mapM parPartToInlines parparts >>= - (return . fromList . trimLineBreaks . normalizeSpaces . toList) + ils <- (trimSps . smushInlines) <$> mapM parPartToInlines parparts dropIls <- gets docxDropCap let ils' = dropIls <> ils if dropCap pPr |