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.
This commit is contained in:
parent
ab1bee58e5
commit
cdbe45e8ee
5 changed files with 47 additions and 2 deletions
|
@ -76,6 +76,7 @@ import Data.Maybe (maybeToList, fromMaybe)
|
|||
import Text.Pandoc.Highlighting
|
||||
import qualified Data.Text as T
|
||||
import Control.Applicative ((<|>))
|
||||
import Data.Char (isSpace)
|
||||
import Skylighting
|
||||
|
||||
data WriterEnv = WriterEnv { envMetadata :: Meta
|
||||
|
@ -229,7 +230,6 @@ data Paragraph = Paragraph { paraProps :: ParaProps
|
|||
, paraElems :: [ParaElem]
|
||||
} deriving (Show, Eq)
|
||||
|
||||
|
||||
data BulletType = Bullet
|
||||
| AutoNumbering ListAttributes
|
||||
deriving (Show, Eq)
|
||||
|
@ -853,6 +853,41 @@ replaceAnchor (Run rProps s)
|
|||
return $ Run rProps' s
|
||||
replaceAnchor pe = return pe
|
||||
|
||||
emptyParaElem :: ParaElem -> Bool
|
||||
emptyParaElem (Run _ s) =
|
||||
null $ dropWhile isSpace $ reverse $ dropWhile isSpace $ reverse s
|
||||
emptyParaElem (MathElem _ ts) =
|
||||
null $ dropWhile isSpace $ reverse $ dropWhile isSpace $ reverse $ unTeXString ts
|
||||
emptyParaElem _ = False
|
||||
|
||||
emptyParagraph :: Paragraph -> Bool
|
||||
emptyParagraph para = all emptyParaElem $ paraElems para
|
||||
|
||||
|
||||
emptyShape :: Shape -> Bool
|
||||
emptyShape (TextBox paras) = all emptyParagraph $ paras
|
||||
emptyShape _ = False
|
||||
|
||||
emptyLayout :: Layout -> Bool
|
||||
emptyLayout layout = case layout of
|
||||
MetadataSlide title subtitle authors date ->
|
||||
all emptyParaElem title &&
|
||||
all emptyParaElem subtitle &&
|
||||
all (all emptyParaElem) authors &&
|
||||
all emptyParaElem date
|
||||
TitleSlide hdr -> all emptyParaElem hdr
|
||||
ContentSlide hdr shapes ->
|
||||
all emptyParaElem hdr &&
|
||||
all emptyShape shapes
|
||||
TwoColumnSlide hdr shapes1 shapes2 ->
|
||||
all emptyParaElem hdr &&
|
||||
all emptyShape shapes1 &&
|
||||
all emptyShape shapes2
|
||||
|
||||
emptySlide :: Slide -> Bool
|
||||
emptySlide (Slide _ layout Nothing) = emptyLayout layout
|
||||
emptySlide _ = False
|
||||
|
||||
blocksToPresentationSlides :: [Block] -> Pres [Slide]
|
||||
blocksToPresentationSlides blks = do
|
||||
opts <- asks envOpts
|
||||
|
@ -893,7 +928,8 @@ blocksToPresentationSlides blks = do
|
|||
return [endNotesSlide]
|
||||
|
||||
let slides = metadataslides ++ tocSlides ++ bodyslides ++ endNotesSlides
|
||||
mapM (applyToSlide replaceAnchor) slides
|
||||
slides' = filter (not . emptySlide) slides
|
||||
mapM (applyToSlide replaceAnchor) slides'
|
||||
|
||||
metaToDocProps :: Meta -> DocProps
|
||||
metaToDocProps meta =
|
||||
|
|
|
@ -77,4 +77,8 @@ tests = groupPptxTests [ pptxTests "Inline formatting"
|
|||
def
|
||||
"pptx/speaker_notes.native"
|
||||
"pptx/speaker_notes.pptx"
|
||||
, pptxTests "remove empty slides"
|
||||
def
|
||||
"pptx/remove_empty_slides.native"
|
||||
"pptx/remove_empty_slides.pptx"
|
||||
]
|
||||
|
|
5
test/pptx/remove_empty_slides.native
Normal file
5
test/pptx/remove_empty_slides.native
Normal file
|
@ -0,0 +1,5 @@
|
|||
[Para [Str "Content"]
|
||||
,Para [Image ("",[],[]) [] ("lalune.jpg",""),Space,RawInline (Format "html") "<!-- -->"]
|
||||
,HorizontalRule
|
||||
,HorizontalRule
|
||||
,Para [Str "More",Space,Str "content"]]
|
BIN
test/pptx/remove_empty_slides.pptx
Normal file
BIN
test/pptx/remove_empty_slides.pptx
Normal file
Binary file not shown.
BIN
test/pptx/remove_empty_slides_templated.pptx
Normal file
BIN
test/pptx/remove_empty_slides_templated.pptx
Normal file
Binary file not shown.
Loading…
Add table
Reference in a new issue