git.iko.soy/typeable/pandoc
on master help sign in
Pptx writer: Apply speaker snotes to metadata slide if applicable.

If the slide deck has a metadata slide (with author, title, etc) and has speaker notes before any body content, the speaker notes will be applied to the metadata slide. If there is no metadata slide, pandoc will behave as before.

commitf72a67efdd0ad50caa32b6d637d019b53e1931fe authorJesse Rosenthal <jrosenthal@jhu.edu> dateSun 31 Mar 2019, 16:59 (8 years ago) parent9d1a4d1
1 file changed+35−15
src/Text/Pandoc/Writers/Powerpoint/Presentation.hs+35−15
src/Text/Pandoc/Writers/Powerpoint/Presentation.hs+35−15
@@ -680,28 +680,32 @@ blocksToSlide' _ [] spkNotes = do
680680 }
681681 spkNotes
682682
683−handleNotes :: Block -> Pres ()
684−handleNotes (Div (_, ["notes"], _) blks) =
685− local (\env -> env{envInSpeakerNotes=True}) $ do
686− spNotes <- SpeakerNotes <$> concatMapM blockToParagraphs blks
683+blockToSpeakerNotes :: Block -> Pres SpeakerNotes
684+blockToSpeakerNotes (Div (_, ["notes"], _) blks) =
685+ local (\env -> env{envInSpeakerNotes=True}) $
686+ SpeakerNotes <$> concatMapM blockToParagraphs blks
687+blockToSpeakerNotes _ = return mempty
688+
689+handleSpeakerNotes :: Block -> Pres ()
690+handleSpeakerNotes blk = do
691+ spNotes <- blockToSpeakerNotes blk
687692 modify $ \st -> st{stSpeakerNotes = (stSpeakerNotes st) <> spNotes}
688−handleNotes _ = return ()
689693
690−handleAndFilterNotes' :: [Block] -> Pres [Block]
691−handleAndFilterNotes' blks = do
692− mapM_ handleNotes blks
694+handleAndFilterSpeakerNotes' :: [Block] -> Pres [Block]
695+handleAndFilterSpeakerNotes' blks = do
696+ mapM_ handleSpeakerNotes blks
693697 return $ filter (not . isNotesDiv) blks
694698
695−handleAndFilterNotes :: [Block] -> Pres ([Block], SpeakerNotes)
696−handleAndFilterNotes blks = do
699+handleAndFilterSpeakerNotes :: [Block] -> Pres ([Block], SpeakerNotes)
700+handleAndFilterSpeakerNotes blks = do
697701 modify $ \st -> st{stSpeakerNotes = mempty}
698− blks' <- walkM handleAndFilterNotes' blks
702+ blks' <- walkM handleAndFilterSpeakerNotes' blks
699703 spkNotes <- gets stSpeakerNotes
700704 return (blks', spkNotes)
701705
702706blocksToSlide :: [Block] -> Pres Slide
703707blocksToSlide blks = do
704− (blks', spkNotes) <- handleAndFilterNotes blks
708+ (blks', spkNotes) <- handleAndFilterSpeakerNotes blks
705709 slideLevel <- asks envSlideLevel
706710 blocksToSlide' slideLevel blks' spkNotes
707711
@@ -759,6 +763,13 @@ getMetaSlide = do
759763 }
760764 mempty
761765
766+addSpeakerNotesToMetaSlide :: Slide -> [Block] -> Pres (Slide, [Block])
767+addSpeakerNotesToMetaSlide (Slide sldId layout@(MetadataSlide _ _ _ _) spkNotes) blks =
768+ do let (ntsBlks, blks') = span isNotesDiv blks
769+ spkNotes' <- mconcat <$> mapM blockToSpeakerNotes ntsBlks
770+ return (Slide sldId layout (spkNotes <> spkNotes'), blks')
771+addSpeakerNotesToMetaSlide sld blks = return (sld, blks)
772+
762773makeTOCSlide :: [Block] -> Pres Slide
763774makeTOCSlide blks = local (\env -> env{envCurSlideId = tocSlideId}) $ do
764775 opts <- asks envOpts
@@ -871,7 +882,16 @@ emptySlide (Slide _ layout notes) = (notes == mempty) && (emptyLayout layout)
871882blocksToPresentationSlides :: [Block] -> Pres [Slide]
872883blocksToPresentationSlides blks = do
873884 opts <- asks envOpts
874− metadataslides <- maybeToList <$> getMetaSlide
885+ mbMetadataSlide <- getMetaSlide
886+ -- if the metadata slide exists, we try to add any speakerNotes
887+ -- which immediately follow it. We also convert from maybe to a
888+ -- list, so that it will be able to add together more easily with
889+ -- the other lists of slides.
890+ (metadataslides, blks') <- case mbMetadataSlide of
891+ Just sld ->
892+ do (s, bs) <- addSpeakerNotesToMetaSlide sld blks
893+ return ([s], bs)
894+ Nothing -> return ([], blks)
875895 -- As far as I can tell, if we want to have a variable-length toc in
876896 -- the future, we'll have to make it twice. Once to get the length,
877897 -- and a second time to include the notes slide. We can't make the
@@ -882,7 +902,7 @@ blocksToPresentationSlides blks = do
882902 -- For now, though, since the TOC slide is only length 1, if it
883903 -- exists, we'll just get the length, and then come back to make the
884904 -- slide later
885− blksLst <- splitBlocks blks
905+ blksLst <- splitBlocks blks'
886906 bodySlideIds <- mapM
887907 (\n -> runUniqueSlideId $ "BodySlide" ++ show n)
888908 (take (length blksLst) [1..] :: [Integer])
@@ -893,7 +913,7 @@ blocksToPresentationSlides blks = do
893913 endNotesSlideBlocks <- makeEndNotesSlideBlocks
894914 -- now we come back and make the real toc...
895915 tocSlides <- if writerTableOfContents opts
896− then do toc <- makeTOCSlide $ blks ++ endNotesSlideBlocks
916+ then do toc <- makeTOCSlide $ blks' ++ endNotesSlideBlocks
897917 return [toc]
898918 else return []
899919 -- ... and the notes slide. We test to see if the blocks are empty,