aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2021-10-04 12:18:18 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2021-10-04 12:24:12 -0700
commitb8d460eeabe97756d49e4bc5f00c6bb084b69aa5 (patch)
treecdb90c7e6034c56b35ad87f99cc372ddbd8fba5a /src/Text
parent11baeb88505342c580cc3dd0263c4ba97e6ddb8a (diff)
downloadpandoc-b8d460eeabe97756d49e4bc5f00c6bb084b69aa5.tar.gz
Powerpoint writer: consolidate text runs when possible.
This slims down the output files by avoiding unnecessary text run elements. Updated golden tests.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Writers/Powerpoint/Output.hs11
-rw-r--r--src/Text/Pandoc/Writers/Powerpoint/Presentation.hs2
2 files changed, 9 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Writers/Powerpoint/Output.hs b/src/Text/Pandoc/Writers/Powerpoint/Output.hs
index f4700e8c1..42ce780fa 100644
--- a/src/Text/Pandoc/Writers/Powerpoint/Output.hs
+++ b/src/Text/Pandoc/Writers/Powerpoint/Output.hs
@@ -1088,6 +1088,12 @@ makePicElements layout picProps mInfo titleText alt = do
return [picShape, cap]
else return [picShape]
+consolidateRuns :: [ParaElem] -> [ParaElem]
+consolidateRuns [] = []
+consolidateRuns (Run pr1 s1 : Run pr2 s2 : xs)
+ | pr1 == pr2 = consolidateRuns (Run pr1 (s1 <> s2) : xs)
+consolidateRuns (x:xs) = x : consolidateRuns xs
+
paraElemToElements :: PandocMonad m => ParaElem -> P m [Content]
paraElemToElements Break = return [Elem $ mknode "a:br" [] ()]
@@ -1223,9 +1229,8 @@ paragraphToElement par = do
[mknode "a:buAutoNum" (autoNumAttrs attrs') ()]
Nothing -> [mknode "a:buNone" [] ()]
)
- paras <- mapM paraElemToElements (paraElems par)
- return $ mknode "a:p" [] $
- [Elem $ mknode "a:pPr" attrs props] <> concat paras
+ paras <- mconcat <$> mapM paraElemToElements (consolidateRuns (paraElems par))
+ return $ mknode "a:p" [] $ [Elem $ mknode "a:pPr" attrs props] <> paras
shapeToElement :: PandocMonad m => Element -> Shape -> P m (Maybe ShapeId, Element)
shapeToElement layout (TextBox paras)
diff --git a/src/Text/Pandoc/Writers/Powerpoint/Presentation.hs b/src/Text/Pandoc/Writers/Powerpoint/Presentation.hs
index e3d31d099..99b016a63 100644
--- a/src/Text/Pandoc/Writers/Powerpoint/Presentation.hs
+++ b/src/Text/Pandoc/Writers/Powerpoint/Presentation.hs
@@ -348,7 +348,7 @@ instance Default PicProps where
--------------------------------------------------
inlinesToParElems :: [Inline] -> Pres [ParaElem]
-inlinesToParElems ils = concatMapM inlineToParElems ils
+inlinesToParElems = concatMapM inlineToParElems
inlineToParElems :: Inline -> Pres [ParaElem]
inlineToParElems (Str s) = do