git.iko.soy/typeable/pandoc
on master help sign in
Powerpoint writer: code cleanup.
commit2582de5384c80369a0bf5dcefba641505e1ca7be authorJesse Rosenthal <jrosenthal@jhu.edu> dateSun 25 Mar 2018, 10:22 (9 years ago) parent4a8993f
1 file changed+17−39
src/Text/Pandoc/Writers/Powerpoint/Presentation.hs+17−39
src/Text/Pandoc/Writers/Powerpoint/Presentation.hs+17−39
@@ -401,10 +401,7 @@ noteSize :: Pixels
401401noteSize = 18
402402
403403blockToParagraphs :: Block -> Pres [Paragraph]
404−blockToParagraphs (Plain ils) = do
405− parElems <- inlinesToParElems ils
406− pProps <- asks envParaProps
407− return [Paragraph pProps parElems]
404+blockToParagraphs (Plain ils) = blockToParagraphs (Para ils)
408405blockToParagraphs (Para ils) = do
409406 parElems <- inlinesToParElems ils
410407 pProps <- asks envParaProps
@@ -519,14 +516,9 @@ withAttr attr (Pic picPr url caption) =
519516withAttr _ sp = sp
520517
521518blockToShape :: Block -> Pres Shape
522−blockToShape (Plain (il:_)) | Image attr ils (url, _) <- il =
523− (withAttr attr . Pic def url) <$> inlinesToParElems ils
519+blockToShape (Plain ils) = blockToShape (Para ils)
524520blockToShape (Para (il:_)) | Image attr ils (url, _) <- il =
525521 (withAttr attr . Pic def url) <$> inlinesToParElems ils
526−blockToShape (Plain (il:_)) | Link _ (il':_) target <- il
527− , Image attr ils (url, _) <- il' =
528− (withAttr attr . Pic def {picPropLink = Just $ ExternalTarget target} url) <$>
529− inlinesToParElems ils
530522blockToShape (Para (il:_)) | Link _ (il':_) target <- il
531523 , Image attr ils (url, _) <- il' =
532524 (withAttr attr . Pic def{picPropLink = Just $ ExternalTarget target} url) <$>
@@ -550,7 +542,6 @@ blockToShape blk = do paras <- blockToParagraphs blk
550542
551543combineShapes :: [Shape] -> [Shape]
552544combineShapes [] = []
553−combineShapes[s] = [s]
554545combineShapes (pic@Pic{} : ss) = pic : combineShapes ss
555546combineShapes (TextBox [] : ss) = combineShapes ss
556547combineShapes (s : TextBox [] : ss) = combineShapes (s : ss)
@@ -639,9 +630,9 @@ blocksToSlide' _ (blk : blks) spkNotes
639630 , Div (_, clsL, _) blksL : Div (_, clsR, _) blksR : remaining <- divBlks
640631 , "column" `elem` clsL, "column" `elem` clsR = do
641632 unless (null blks)
642− (mapM (addLogMessage . BlockNotRendered) blks >> return ())
633+ (mapM_ (addLogMessage . BlockNotRendered) blks >> return ())
643634 unless (null remaining)
644− (mapM (addLogMessage . BlockNotRendered) remaining >> return ())
635+ (mapM_ (addLogMessage . BlockNotRendered) remaining >> return ())
645636 mbSplitBlksL <- splitBlocks blksL
646637 mbSplitBlksR <- splitBlocks blksR
647638 let blksL' = case mbSplitBlksL of
@@ -732,15 +723,14 @@ makeEndNotesSlideBlocks = do
732723 anchorSet <- M.keysSet <$> gets stAnchorMap
733724 if M.null noteIds
734725 then return []
735− else do let title = case lookupMeta "notes-title" meta of
736− Just val -> metaValueToInlines val
737− Nothing -> [Str "Notes"]
738− ident = Shared.uniqueIdent title anchorSet
739− hdr = Header slideLevel (ident, [], []) title
740− blks <- return $
741− concatMap (\(n, bs) -> makeNoteEntry n bs) $
726+ else let title = case lookupMeta "notes-title" meta of
727+ Just val -> metaValueToInlines val
728+ Nothing -> [Str "Notes"]
729+ ident = Shared.uniqueIdent title anchorSet
730+ hdr = Header slideLevel (ident, [], []) title
731+ blks = concatMap (\(n, bs) -> makeNoteEntry n bs) $
742732 M.toList noteIds
743− return $ hdr : blks
733+ in return $ hdr : blks
744734
745735getMetaSlide :: Pres (Maybe Slide)
746736getMetaSlide = do
@@ -791,8 +781,7 @@ makeTOCSlide blks = local (\env -> env{envCurSlideId = tocSlideId}) $ do
791781 Just val -> metaValueToInlines val
792782 Nothing -> [Str "Table of Contents"]
793783 hdr = Header slideLevel nullAttr tocTitle
794− sld <- blocksToSlide [hdr, contents]
795− return sld
784+ blocksToSlide [hdr, contents]
796785
797786combineParaElems' :: Maybe ParaElem -> [ParaElem] -> [ParaElem]
798787combineParaElems' mbPElem [] = maybeToList mbPElem
@@ -815,15 +804,9 @@ applyToParagraph f para = do
815804 return $ para {paraElems = paraElems'}
816805
817806applyToShape :: Monad m => (ParaElem -> m ParaElem) -> Shape -> m Shape
818−applyToShape f (Pic pPr fp pes) = do
819− pes' <- mapM f pes
820− return $ Pic pPr fp pes'
821−applyToShape f (GraphicFrame gfx pes) = do
822− pes' <- mapM f pes
823− return $ GraphicFrame gfx pes'
824−applyToShape f (TextBox paras) = do
825− paras' <- mapM (applyToParagraph f) paras
826− return $ TextBox paras'
807+applyToShape f (Pic pPr fp pes) = Pic pPr fp <$> mapM f pes
808+applyToShape f (GraphicFrame gfx pes) = GraphicFrame gfx <$> mapM f pes
809+applyToShape f (TextBox paras) = TextBox <$> mapM (applyToParagraph f) paras
827810
828811applyToLayout :: Monad m => (ParaElem -> m ParaElem) -> Layout -> m Layout
829812applyToLayout f (MetadataSlide title subtitle authors date) = do
@@ -832,9 +815,7 @@ applyToLayout f (MetadataSlide title subtitle authors date) = do
832815 authors' <- mapM (mapM f) authors
833816 date' <- mapM f date
834817 return $ MetadataSlide title' subtitle' authors' date'
835−applyToLayout f (TitleSlide title) = do
836− title' <- mapM f title
837− return $ TitleSlide title'
818+applyToLayout f (TitleSlide title) = TitleSlide <$> mapM f title
838819applyToLayout f (ContentSlide hdr content) = do
839820 hdr' <- mapM f hdr
840821 content' <- mapM (applyToShape f) content
@@ -896,10 +877,7 @@ emptyLayout layout = case layout of
896877 all emptyShape shapes2
897878
898879emptySlide :: Slide -> Bool
899−emptySlide (Slide _ layout notes) =
900− if notes == mempty
901− then emptyLayout layout
902− else False
880+emptySlide (Slide _ layout notes) = (notes == mempty) && (emptyLayout layout)
903881
904882blocksToPresentationSlides :: [Block] -> Pres [Slide]
905883blocksToPresentationSlides blks = do