From ab184a519c75b2258a375a48ab123c5c2270e3bf Mon Sep 17 00:00:00 2001 From: Jesse Rosenthal Date: Wed, 21 Mar 2018 09:37:49 -0400 Subject: Powerpoint writer: handle speaker notes earlier in the conversion process Internal change: We were getting bad results with the empty text box created by the conversion of notes into an empty paragraph. So we now convert the notes at the `blocksToSlide` stage, by `walkM`ing a function over the blocks that returns `()`, and then filters the notes out. This avoids the need to have a return value for speaker notes, and thus avoids the empty TextBox. Together with the previous commit (256f14c5a), closes #4477. --- src/Text/Pandoc/Writers/Powerpoint/Presentation.hs | 38 +++++++++++++--------- 1 file changed, 23 insertions(+), 15 deletions(-) (limited to 'src/Text/Pandoc/Writers') diff --git a/src/Text/Pandoc/Writers/Powerpoint/Presentation.hs b/src/Text/Pandoc/Writers/Powerpoint/Presentation.hs index 550071600..6d2c0834b 100644 --- a/src/Text/Pandoc/Writers/Powerpoint/Presentation.hs +++ b/src/Text/Pandoc/Writers/Powerpoint/Presentation.hs @@ -476,16 +476,6 @@ blockToParagraphs (DefinitionList entries) = do definition <- concatMapM (blockToParagraphs . BlockQuote) blksLst return $ term ++ definition concatMapM go entries -blockToParagraphs (Div (_, ["notes"], _) blks) = - local (\env -> env{envInSpeakerNotes=True}) $ do - sldId <- asks envCurSlideId - spkNotesMap <- gets stSpeakerNotesMap - paras <- concatMapM blockToParagraphs blks - let spkNotesMap' = case M.lookup sldId spkNotesMap of - Just lst -> M.insert sldId (paras : lst) spkNotesMap - Nothing -> M.insert sldId [paras] spkNotesMap - modify $ \st -> st{stSpeakerNotesMap = spkNotesMap'} - return [] blockToParagraphs (Div _ blks) = concatMapM blockToParagraphs blks blockToParagraphs blk = do addLogMessage $ BlockNotRendered blk @@ -567,6 +557,27 @@ combineShapes (TextBox (p:ps) : TextBox (p':ps') : ss) = combineShapes $ TextBox ((p:ps) ++ (p':ps')) : ss combineShapes (s:ss) = s : combineShapes ss +isNotesDiv :: Block -> Bool +isNotesDiv (Div (_, ["notes"], _) _) = True +isNotesDiv _ = False + +handleNotes :: Block -> Pres () +handleNotes (Div (_, ["notes"], _) blks) = + local (\env -> env{envInSpeakerNotes=True}) $ do + sldId <- asks envCurSlideId + spkNotesMap <- gets stSpeakerNotesMap + paras <- concatMapM blockToParagraphs blks + let spkNotesMap' = case M.lookup sldId spkNotesMap of + Just lst -> M.insert sldId (paras : lst) spkNotesMap + Nothing -> M.insert sldId [paras] spkNotesMap + modify $ \st -> st{stSpeakerNotesMap = spkNotesMap'} +handleNotes _ = return () + +handleAndFilterNotes :: [Block] -> Pres [Block] +handleAndFilterNotes blks = do + mapM_ handleNotes blks + return $ filter (not . isNotesDiv) blks + blocksToShapes :: [Block] -> Pres [Shape] blocksToShapes blks = combineShapes <$> mapM blockToShape blks @@ -575,10 +586,6 @@ isImage Image{} = True isImage (Link _ (Image{} : _) _) = True isImage _ = False -isNotesDiv :: Block -> Bool -isNotesDiv (Div (_, ["notes"], _) _) = True -isNotesDiv _ = False - splitBlocks' :: [Block] -> [[Block]] -> [Block] -> Pres [[Block]] splitBlocks' cur acc [] = return $ acc ++ (if null cur then [] else [cur]) splitBlocks' cur acc (HorizontalRule : blks) = @@ -701,7 +708,8 @@ blocksToSlide' _ [] = do blocksToSlide :: [Block] -> Pres Slide blocksToSlide blks = do slideLevel <- asks envSlideLevel - sld <- blocksToSlide' slideLevel blks + blks' <- walkM handleAndFilterNotes blks + sld <- blocksToSlide' slideLevel blks' spkNotes <- getSpeakerNotes return $ sld{slideSpeakerNotes = spkNotes} -- cgit v1.2.3