@@ -35,7 +35,6 @@ Presentation.
3535module Text.Pandoc.Writers.Powerpoint.Presentation ( documentToPresentation
3636 , Presentation(..)
3737 , Slide(..)
38− , SlideElement(..)
3938 , Shape(..)
4039 , Graphic(..)
4140 , BulletType(..)
@@ -50,6 +49,7 @@ module Text.Pandoc.Writers.Powerpoint.Presentation ( documentToPresentation
5049 , PicProps(..)
5150 , URL
5251 , TeXString(..)
52+ , LinkTarget(..)
5353 ) where
5454
5555
@@ -78,10 +78,6 @@ data WriterEnv = WriterEnv { envMetadata :: Meta
7878 , envInList :: Bool
7979 , envInNoteSlide :: Bool
8080 , envCurSlideId :: Int
81− -- the difference between the number at
82− -- the end of the slide file name and
83− -- the rId number
84− , envSlideIdOffset :: Int
8581 }
8682 deriving (Show)
8783
@@ -95,7 +91,6 @@ instance Default WriterEnv where
9591 , envInList = False
9692 , envInNoteSlide = False
9793 , envCurSlideId = 1
98− , envSlideIdOffset = 1
9994 }
10095
10196
@@ -139,9 +134,6 @@ data Slide = MetadataSlide { metadataSlideTitle :: [ParaElem]
139134 }
140135 deriving (Show, Eq)
141136
142−data SlideElement = SlideElement Pixels Pixels Pixels Pixels Shape
143− deriving (Show, Eq)
144−
145137data Shape = Pic PicProps FilePath Text.Pandoc.Definition.Attr [ParaElem]
146138 | GraphicFrame [Graphic] [ParaElem]
147139 | TextBox [Paragraph]
@@ -206,12 +198,16 @@ data Capitals = NoCapitals | SmallCapitals | AllCapitals
206198
207199type URL = String
208200
201+data LinkTarget = ExternalTarget (URL, String)
202+ | InternalTarget Int -- slideId
203+ deriving (Show, Eq)
204+
209205data RunProps = RunProps { rPropBold :: Bool
210206 , rPropItalics :: Bool
211207 , rStrikethrough :: Maybe Strikethrough
212208 , rBaseline :: Maybe Int
213209 , rCap :: Maybe Capitals
214− , rLink :: Maybe (URL, String)
210+ , rLink :: Maybe LinkTarget
215211 , rPropCode :: Bool
216212 , rPropBlockQuote :: Bool
217213 , rPropForceSize :: Maybe Pixels
@@ -229,7 +225,7 @@ instance Default RunProps where
229225 , rPropForceSize = Nothing
230226 }
231227
232−data PicProps = PicProps { picPropLink :: Maybe (URL, String)
228+data PicProps = PicProps { picPropLink :: Maybe LinkTarget
233229 } deriving (Show, Eq)
234230
235231instance Default PicProps where
@@ -267,7 +263,7 @@ inlineToParElems Space = inlineToParElems (Str " ")
267263inlineToParElems SoftBreak = inlineToParElems (Str " ")
268264inlineToParElems LineBreak = return [Break]
269265inlineToParElems (Link _ ils (url, title)) = do
270− local (\r ->r{envRunProps = (envRunProps r){rLink = Just (url, title)}}) $
266+ local (\r ->r{envRunProps = (envRunProps r){rLink = Just $ ExternalTarget (url, title)}}) $
271267 inlinesToParElems ils
272268inlineToParElems (Code _ str) = do
273269 local (\r ->r{envRunProps = (envRunProps r){rPropCode = True}}) $
@@ -414,10 +410,10 @@ blockToShape (Para (il:_)) | Image attr ils (url, _) <- il =
414410 Pic def url attr <$> (inlinesToParElems ils)
415411blockToShape (Plain (il:_)) | Link _ (il':_) target <- il
416412 , Image attr ils (url, _) <- il' =
417− Pic def{picPropLink = Just target} url attr <$> (inlinesToParElems ils)
413+ Pic def{picPropLink = Just $ ExternalTarget target} url attr <$> (inlinesToParElems ils)
418414blockToShape (Para (il:_)) | Link _ (il':_) target <- il
419415 , Image attr ils (url, _) <- il' =
420− Pic def{picPropLink = Just target} url attr <$> (inlinesToParElems ils)
416+ Pic def{picPropLink = Just $ ExternalTarget target} url attr <$> (inlinesToParElems ils)
421417blockToShape (Table caption algn _ hdrCells rows) = do
422418 caption' <- inlinesToParElems caption
423419 hdrCells' <- rowToParagraphs algn hdrCells
@@ -644,6 +640,51 @@ combineParaElems' (Just pElem') (pElem : pElems)
644640combineParaElems :: [ParaElem] -> [ParaElem]
645641combineParaElems = combineParaElems' Nothing
646642
643+applyToParagraph :: Monad m => (ParaElem -> m ParaElem) -> Paragraph -> m Paragraph
644+applyToParagraph f para = do
645+ paraElems' <- mapM f $ paraElems para
646+ return $ para {paraElems = paraElems'}
647+
648+applyToShape :: Monad m => (ParaElem -> m ParaElem) -> Shape -> m Shape
649+applyToShape f (Pic pPr fp attr pes) = do
650+ pes' <- mapM f pes
651+ return $ Pic pPr fp attr pes'
652+applyToShape f (GraphicFrame gfx pes) = do
653+ pes' <- mapM f pes
654+ return $ GraphicFrame gfx pes'
655+applyToShape f (TextBox paras) = do
656+ paras' <- mapM (applyToParagraph f) paras
657+ return $ TextBox paras'
658+
659+applyToSlide :: Monad m => (ParaElem -> m ParaElem) -> Slide -> m Slide
660+applyToSlide f (MetadataSlide title subtitle authors date) = do
661+ title' <- mapM f title
662+ subtitle' <- mapM f subtitle
663+ authors' <- mapM (mapM f) authors
664+ date' <- mapM f date
665+ return $ MetadataSlide title' subtitle' authors' date'
666+applyToSlide f (TitleSlide title) = do
667+ title' <- mapM f title
668+ return $ TitleSlide title'
669+applyToSlide f (ContentSlide hdr content) = do
670+ hdr' <- mapM f hdr
671+ content' <- mapM (applyToShape f) content
672+ return $ ContentSlide hdr' content'
673+applyToSlide f (TwoColumnSlide hdr contentL contentR) = do
674+ hdr' <- mapM f hdr
675+ contentL' <- mapM (applyToShape f) contentL
676+ contentR' <- mapM (applyToShape f) contentR
677+ return $ TwoColumnSlide hdr' contentL' contentR'
678+
679+replaceAnchor :: PandocMonad m => ParaElem -> Pres m ParaElem
680+replaceAnchor (Run rProps s)
681+ | Just (ExternalTarget ('#':anchor, _)) <- rLink rProps = do
682+ anchorMap <- gets stAnchorMap
683+ return $ case M.lookup anchor anchorMap of
684+ Just n -> Run (rProps{rLink = Just $ InternalTarget n}) s
685+ Nothing -> Run rProps s
686+replaceAnchor pe = return pe
687+
647688blocksToPresentation :: PandocMonad m => [Block] -> Pres m Presentation
648689blocksToPresentation blks = do
649690 opts <- asks envOpts
@@ -683,9 +724,10 @@ blocksToPresentation blks = do
683724 })
684725 (blocksToSlide $ notesSlideBlocks)
685726 return [notesSlide]
686− return $
687− Presentation $
688− metadataslides ++ tocSlides ++ bodyslides ++ notesSlides
727+
728+ let slides = metadataslides ++ tocSlides ++ bodyslides ++ notesSlides
729+ slides' <- mapM (applyToSlide replaceAnchor) slides
730+ return $ Presentation slides'
689731
690732documentToPresentation :: PandocMonad m
691733 => WriterOptions