aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJesse Rosenthal <jrosenthal@jhu.edu>2018-03-21 09:37:49 -0400
committerJesse Rosenthal <jrosenthal@jhu.edu>2018-03-21 10:07:07 -0400
commitab184a519c75b2258a375a48ab123c5c2270e3bf (patch)
tree31929fa595b6525cf76ff8cc2112a30679cf129c /src
parentcb1ee07c9819bafa48a62c518e94cc95281697c1 (diff)
downloadpandoc-ab184a519c75b2258a375a48ab123c5c2270e3bf.tar.gz
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.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Writers/Powerpoint/Presentation.hs38
1 files changed, 23 insertions, 15 deletions
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}