git.iko.soy/typeable/pandoc
on master help sign in
Powerpoint writer: Include Notes slide in TOC
f130109Jesse Rosenthal
src/Text/Pandoc/Writers/Powerpoint.hs+42−19
@@ -638,25 +638,26 @@ forceFontSize px x = do
638 rpr <- asks envRunProps
638 rpr <- asks envRunProps
639 local (\r -> r {envRunProps = rpr{rPropForceSize = Just px}}) x
639 local (\r -> r {envRunProps = rpr{rPropForceSize = Just px}}) x
640
640
641−-- Right now, there's no logic for making more than one slide, but I
641+-- We leave these as blocks because we will want to include them in
642−-- want to leave the option open to make multiple slides if we figure
642+-- the TOC.
643−-- out how to guess at how much space the text of the notes will take
643+makeNotesSlideBlocks :: PandocMonad m => P m [Block]
644−-- up (or if we allow a way for it to be manually controlled). Plus a
644+makeNotesSlideBlocks = do
645−-- list will make it easier to put together in the final
646−-- `blocksToPresentation` function (since we can just add an empty
647−-- list without checking the state).
648−makeNotesSlides :: PandocMonad m => P m [Slide]
649−makeNotesSlides = local (\env -> env{envInNoteSlide=True}) $ do
650 noteIds <- gets stNoteIds
645 noteIds <- gets stNoteIds
651 slideLevel <- asks envSlideLevel
646 slideLevel <- asks envSlideLevel
647+ meta <- asks envMetadata
648+ -- Get identifiers so we can give the notes section a unique ident.
649+ anchorSet <- M.keysSet <$> gets stAnchorMap
652 if M.null noteIds
650 if M.null noteIds
653 then return []
651 then return []
652+ else do let title = case lookupMeta "notes-title" meta of
653+ Just val -> metaValueToInlines val
654+ Nothing -> [Str "Notes"]
655+ ident = Shared.uniqueIdent title anchorSet
654− else do let hdr = Header slideLevel nullAttr [Str "Notes"]
656+ hdr = Header slideLevel (ident, [], []) title
655 blks <- return $
657 blks <- return $
656 concatMap (\(n, bs) -> makeNoteEntry n bs) $
658 concatMap (\(n, bs) -> makeNoteEntry n bs) $
657 M.toList noteIds
659 M.toList noteIds
658− sld <- blocksToSlide $ hdr : blks
660+ return $ hdr : blks
659− return [sld]
660
661
661getMetaSlide :: PandocMonad m => P m (Maybe Slide)
662getMetaSlide :: PandocMonad m => P m (Maybe Slide)
662getMetaSlide = do
663getMetaSlide = do
@@ -711,21 +712,43 @@ blocksToPresentation blks = do
711 let metadataStartNum = 1
712 let metadataStartNum = 1
712 metadataslides <- maybeToList <$> getMetaSlide
713 metadataslides <- maybeToList <$> getMetaSlide
713 let tocStartNum = metadataStartNum + length metadataslides
714 let tocStartNum = metadataStartNum + length metadataslides
715+ -- As far as I can tell, if we want to have a variable-length toc in
716+ -- the future, we'll have to make it twice. Once to get the length,
717+ -- and a second time to include the notes slide. We can't make the
718+ -- notes slide before the body slides because we need to know if
719+ -- there are notes, and we can't make either before the toc slide,
720+ -- because we need to know its length to get slide numbers right.
721+ --
722+ -- For now, though, since the TOC slide is only length 1, if it
723+ -- exists, we'll just get the length, and then come back to make the
724+ -- slide later
714− tocSlides <- if writerTableOfContents opts
725+ let tocSlidesLength = if writerTableOfContents opts then 1 else 0
715− then do toc <- makeTOCSlide blks
716− return [toc]
717− else return []
718− let bodyStartNum = tocStartNum + length tocSlides
726+ let bodyStartNum = tocStartNum + tocSlidesLength
719 blksLst <- splitBlocks blks
727 blksLst <- splitBlocks blks
720 bodyslides <- mapM
728 bodyslides <- mapM
721 (\(bs, n) -> local (\st -> st{envCurSlideId = n}) (blocksToSlide bs))
729 (\(bs, n) -> local (\st -> st{envCurSlideId = n}) (blocksToSlide bs))
722 (zip blksLst [bodyStartNum..])
730 (zip blksLst [bodyStartNum..])
723 let noteStartNum = bodyStartNum + length bodyslides
731 let noteStartNum = bodyStartNum + length bodyslides
732+ notesSlideBlocks <- makeNotesSlideBlocks
733+ -- now we come back and make the real toc...
734+ tocSlides <- if writerTableOfContents opts
735+ then do toc <- makeTOCSlide $ blks ++ notesSlideBlocks
736+ return [toc]
737+ else return []
738+ -- ... and the notes slide. We test to see if the blocks are empty,
739+ -- because we don't want to make an empty slide.
740+ notesSlides <- if null notesSlideBlocks
741+ then return []
742+ else do notesSlide <- local
724− noteSlides <- local (\st -> st {envCurSlideId = noteStartNum}) makeNotesSlides
743+ (\env -> env { envCurSlideId = noteStartNum
744+ , envInNoteSlide = True
745+ })
746+ (blocksToSlide $ notesSlideBlocks)
747+ return [notesSlide]
725 presSize <- asks envPresentationSize
748 presSize <- asks envPresentationSize
726 return $
749 return $
727 Presentation presSize $
750 Presentation presSize $
728− metadataslides ++ tocSlides ++ bodyslides ++ noteSlides
751+ metadataslides ++ tocSlides ++ bodyslides ++ notesSlides
729
752
730--------------------------------------------------------------------
753--------------------------------------------------------------------
731
754