git.iko.soy/typeable/pandoc
on master help sign in
Powerpoint writer: Remove empty slides

Make sure there are no empty slides in the pptx output. Because of the way that slides were split, these could be accidentally produced by comments after images. When animations are added, there will be a way to add an empty slide with either incremental lists or pauses. Test outputs checked with MS PowerPoint (Office 2013, Windows 10, VBox). Both files have expected output and are not corrupted.

commitcdbe45e8ee1c5b87516ad020584576a22fdb28f4 authorJesse Rosenthal <jrosenthal@jhu.edu> dateTue 27 Feb 2018, 09:09 (9 years ago) parentab1bee5
5 files changed+47−2
src/Text/Pandoc/Writers/Powerpoint/Presentation.hs+38−2 test/Tests/Writers/Powerpoint.hs+4 test/pptx/remove_empty_slides.native+5 test/pptx/remove_empty_slides.pptx test/pptx/remove_empty_slides_templated.pptx
src/Text/Pandoc/Writers/Powerpoint/Presentation.hs+38−2
@@ -76,6 +76,7 @@ import Data.Maybe (maybeToList, fromMaybe)
7676import Text.Pandoc.Highlighting
7777import qualified Data.Text as T
7878import Control.Applicative ((<|>))
79+import Data.Char (isSpace)
7980import Skylighting
8081
8182data WriterEnv = WriterEnv { envMetadata :: Meta
@@ -229,7 +230,6 @@ data Paragraph = Paragraph { paraProps :: ParaProps
229230 , paraElems :: [ParaElem]
230231 } deriving (Show, Eq)
231232
232−
233233data BulletType = Bullet
234234 | AutoNumbering ListAttributes
235235 deriving (Show, Eq)
@@ -853,6 +853,41 @@ replaceAnchor (Run rProps s)
853853 return $ Run rProps' s
854854replaceAnchor pe = return pe
855855
856+emptyParaElem :: ParaElem -> Bool
857+emptyParaElem (Run _ s) =
858+ null $ dropWhile isSpace $ reverse $ dropWhile isSpace $ reverse s
859+emptyParaElem (MathElem _ ts) =
860+ null $ dropWhile isSpace $ reverse $ dropWhile isSpace $ reverse $ unTeXString ts
861+emptyParaElem _ = False
862+
863+emptyParagraph :: Paragraph -> Bool
864+emptyParagraph para = all emptyParaElem $ paraElems para
865+
866+
867+emptyShape :: Shape -> Bool
868+emptyShape (TextBox paras) = all emptyParagraph $ paras
869+emptyShape _ = False
870+
871+emptyLayout :: Layout -> Bool
872+emptyLayout layout = case layout of
873+ MetadataSlide title subtitle authors date ->
874+ all emptyParaElem title &&
875+ all emptyParaElem subtitle &&
876+ all (all emptyParaElem) authors &&
877+ all emptyParaElem date
878+ TitleSlide hdr -> all emptyParaElem hdr
879+ ContentSlide hdr shapes ->
880+ all emptyParaElem hdr &&
881+ all emptyShape shapes
882+ TwoColumnSlide hdr shapes1 shapes2 ->
883+ all emptyParaElem hdr &&
884+ all emptyShape shapes1 &&
885+ all emptyShape shapes2
886+
887+emptySlide :: Slide -> Bool
888+emptySlide (Slide _ layout Nothing) = emptyLayout layout
889+emptySlide _ = False
890+
856891blocksToPresentationSlides :: [Block] -> Pres [Slide]
857892blocksToPresentationSlides blks = do
858893 opts <- asks envOpts
@@ -893,7 +928,8 @@ blocksToPresentationSlides blks = do
893928 return [endNotesSlide]
894929
895930 let slides = metadataslides ++ tocSlides ++ bodyslides ++ endNotesSlides
896− mapM (applyToSlide replaceAnchor) slides
931+ slides' = filter (not . emptySlide) slides
932+ mapM (applyToSlide replaceAnchor) slides'
897933
898934metaToDocProps :: Meta -> DocProps
899935metaToDocProps meta =
test/Tests/Writers/Powerpoint.hs+4
@@ -77,4 +77,8 @@ tests = groupPptxTests [ pptxTests "Inline formatting"
7777 def
7878 "pptx/speaker_notes.native"
7979 "pptx/speaker_notes.pptx"
80+ , pptxTests "remove empty slides"
81+ def
82+ "pptx/remove_empty_slides.native"
83+ "pptx/remove_empty_slides.pptx"
8084 ]
test/pptx/remove_empty_slides.nativenew file+5
@@ -0,0 +1,5 @@
1+[Para [Str "Content"]
2+,Para [Image ("",[],[]) [] ("lalune.jpg",""),Space,RawInline (Format "html") "<!-- -->"]
3+,HorizontalRule
4+,HorizontalRule
5+,Para [Str "More",Space,Str "content"]]
test/pptx/remove_empty_slides.pptxnew file

Binary file not shown.

test/pptx/remove_empty_slides_templated.pptxnew file

Binary file not shown.