git.iko.soy/typeable/pandoc
on master help sign in
Powerpoint writer: Remove empty slides
cdbe45eJesse Rosenthal
src/Text/Pandoc/Writers/Powerpoint/Presentation.hs+38−2
@@ -76,6 +76,7 @@ import Data.Maybe (maybeToList, fromMaybe)
76import Text.Pandoc.Highlighting
76import Text.Pandoc.Highlighting
77import qualified Data.Text as T
77import qualified Data.Text as T
78import Control.Applicative ((<|>))
78import Control.Applicative ((<|>))
79+import Data.Char (isSpace)
79import Skylighting
80import Skylighting
80
81
81data WriterEnv = WriterEnv { envMetadata :: Meta
82data WriterEnv = WriterEnv { envMetadata :: Meta
@@ -229,7 +230,6 @@ data Paragraph = Paragraph { paraProps :: ParaProps
229 , paraElems :: [ParaElem]
230 , paraElems :: [ParaElem]
230 } deriving (Show, Eq)
231 } deriving (Show, Eq)
231
232
232−
233data BulletType = Bullet
233data BulletType = Bullet
234 | AutoNumbering ListAttributes
234 | AutoNumbering ListAttributes
235 deriving (Show, Eq)
235 deriving (Show, Eq)
@@ -853,6 +853,41 @@ replaceAnchor (Run rProps s)
853 return $ Run rProps' s
853 return $ Run rProps' s
854replaceAnchor pe = return pe
854replaceAnchor pe = return pe
855
855
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+
856blocksToPresentationSlides :: [Block] -> Pres [Slide]
891blocksToPresentationSlides :: [Block] -> Pres [Slide]
857blocksToPresentationSlides blks = do
892blocksToPresentationSlides blks = do
858 opts <- asks envOpts
893 opts <- asks envOpts
@@ -893,7 +928,8 @@ blocksToPresentationSlides blks = do
893 return [endNotesSlide]
928 return [endNotesSlide]
894
929
895 let slides = metadataslides ++ tocSlides ++ bodyslides ++ endNotesSlides
930 let slides = metadataslides ++ tocSlides ++ bodyslides ++ endNotesSlides
931+ slides' = filter (not . emptySlide) slides
896− mapM (applyToSlide replaceAnchor) slides
932+ mapM (applyToSlide replaceAnchor) slides'
897
933
898metaToDocProps :: Meta -> DocProps
934metaToDocProps :: Meta -> DocProps
899metaToDocProps meta =
935metaToDocProps meta =
test/Tests/Writers/Powerpoint.hs+4
@@ -77,4 +77,8 @@ tests = groupPptxTests [ pptxTests "Inline formatting"
77 def
77 def
78 "pptx/speaker_notes.native"
78 "pptx/speaker_notes.native"
79 "pptx/speaker_notes.pptx"
79 "pptx/speaker_notes.pptx"
80+ , pptxTests "remove empty slides"
81+ def
82+ "pptx/remove_empty_slides.native"
83+ "pptx/remove_empty_slides.pptx"
80 ]
84 ]
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.