Powerpoint writer: consolidate text runs when possible.

This slims down the output files by avoiding unnecessary
text run elements.

Updated golden tests.
This commit is contained in:
John MacFarlane 2021-10-04 12:18:18 -07:00
parent 11baeb8850
commit b8d460eeab
138 changed files with 9 additions and 4 deletions

View file

@ -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)

View file

@ -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

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show more