git.iko.soy/typeable/pandoc
on master help sign in
Pptx writer: Apply speaker snotes to metadata slide if applicable.
f72a67eJesse Rosenthal
src/Text/Pandoc/Writers/Powerpoint/Presentation.hs+35−15
@@ -680,28 +680,32 @@ blocksToSlide' _ [] spkNotes = do
680 }
680 }
681 spkNotes
681 spkNotes
682
682
683−handleNotes :: Block -> Pres ()
683+blockToSpeakerNotes :: Block -> Pres SpeakerNotes
684−handleNotes (Div (_, ["notes"], _) blks) =
684+blockToSpeakerNotes (Div (_, ["notes"], _) blks) =
685− local (\env -> env{envInSpeakerNotes=True}) $ do
685+ local (\env -> env{envInSpeakerNotes=True}) $
686− spNotes <- SpeakerNotes <$> concatMapM blockToParagraphs blks
686+ SpeakerNotes <$> concatMapM blockToParagraphs blks
687+blockToSpeakerNotes _ = return mempty
688+
689+handleSpeakerNotes :: Block -> Pres ()
690+handleSpeakerNotes blk = do
691+ spNotes <- blockToSpeakerNotes blk
687 modify $ \st -> st{stSpeakerNotes = (stSpeakerNotes st) <> spNotes}
692 modify $ \st -> st{stSpeakerNotes = (stSpeakerNotes st) <> spNotes}
688−handleNotes _ = return ()
689
693
690−handleAndFilterNotes' :: [Block] -> Pres [Block]
694+handleAndFilterSpeakerNotes' :: [Block] -> Pres [Block]
691−handleAndFilterNotes' blks = do
695+handleAndFilterSpeakerNotes' blks = do
692− mapM_ handleNotes blks
696+ mapM_ handleSpeakerNotes blks
693 return $ filter (not . isNotesDiv) blks
697 return $ filter (not . isNotesDiv) blks
694
698
695−handleAndFilterNotes :: [Block] -> Pres ([Block], SpeakerNotes)
699+handleAndFilterSpeakerNotes :: [Block] -> Pres ([Block], SpeakerNotes)
696−handleAndFilterNotes blks = do
700+handleAndFilterSpeakerNotes blks = do
697 modify $ \st -> st{stSpeakerNotes = mempty}
701 modify $ \st -> st{stSpeakerNotes = mempty}
698− blks' <- walkM handleAndFilterNotes' blks
702+ blks' <- walkM handleAndFilterSpeakerNotes' blks
699 spkNotes <- gets stSpeakerNotes
703 spkNotes <- gets stSpeakerNotes
700 return (blks', spkNotes)
704 return (blks', spkNotes)
701
705
702blocksToSlide :: [Block] -> Pres Slide
706blocksToSlide :: [Block] -> Pres Slide
703blocksToSlide blks = do
707blocksToSlide blks = do
704− (blks', spkNotes) <- handleAndFilterNotes blks
708+ (blks', spkNotes) <- handleAndFilterSpeakerNotes blks
705 slideLevel <- asks envSlideLevel
709 slideLevel <- asks envSlideLevel
706 blocksToSlide' slideLevel blks' spkNotes
710 blocksToSlide' slideLevel blks' spkNotes
707
711
@@ -759,6 +763,13 @@ getMetaSlide = do
759 }
763 }
760 mempty
764 mempty
761
765
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+
762makeTOCSlide :: [Block] -> Pres Slide
773makeTOCSlide :: [Block] -> Pres Slide
763makeTOCSlide blks = local (\env -> env{envCurSlideId = tocSlideId}) $ do
774makeTOCSlide blks = local (\env -> env{envCurSlideId = tocSlideId}) $ do
764 opts <- asks envOpts
775 opts <- asks envOpts
@@ -871,7 +882,16 @@ emptySlide (Slide _ layout notes) = (notes == mempty) && (emptyLayout layout)
871blocksToPresentationSlides :: [Block] -> Pres [Slide]
882blocksToPresentationSlides :: [Block] -> Pres [Slide]
872blocksToPresentationSlides blks = do
883blocksToPresentationSlides blks = do
873 opts <- asks envOpts
884 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)
875 -- As far as I can tell, if we want to have a variable-length toc in
895 -- As far as I can tell, if we want to have a variable-length toc in
876 -- the future, we'll have to make it twice. Once to get the length,
896 -- the future, we'll have to make it twice. Once to get the length,
877 -- and a second time to include the notes slide. We can't make the
897 -- and a second time to include the notes slide. We can't make the
@@ -882,7 +902,7 @@ blocksToPresentationSlides blks = do
882 -- For now, though, since the TOC slide is only length 1, if it
902 -- For now, though, since the TOC slide is only length 1, if it
883 -- exists, we'll just get the length, and then come back to make the
903 -- exists, we'll just get the length, and then come back to make the
884 -- slide later
904 -- slide later
885− blksLst <- splitBlocks blks
905+ blksLst <- splitBlocks blks'
886 bodySlideIds <- mapM
906 bodySlideIds <- mapM
887 (\n -> runUniqueSlideId $ "BodySlide" ++ show n)
907 (\n -> runUniqueSlideId $ "BodySlide" ++ show n)
888 (take (length blksLst) [1..] :: [Integer])
908 (take (length blksLst) [1..] :: [Integer])
@@ -893,7 +913,7 @@ blocksToPresentationSlides blks = do
893 endNotesSlideBlocks <- makeEndNotesSlideBlocks
913 endNotesSlideBlocks <- makeEndNotesSlideBlocks
894 -- now we come back and make the real toc...
914 -- now we come back and make the real toc...
895 tocSlides <- if writerTableOfContents opts
915 tocSlides <- if writerTableOfContents opts
896− then do toc <- makeTOCSlide $ blks ++ endNotesSlideBlocks
916+ then do toc <- makeTOCSlide $ blks' ++ endNotesSlideBlocks
897 return [toc]
917 return [toc]
898 else return []
918 else return []
899 -- ... and the notes slide. We test to see if the blocks are empty,
919 -- ... and the notes slide. We test to see if the blocks are empty,