@@ -72,7 +72,7 @@ import qualified Text.Pandoc.Shared as Shared -- so we don't overlap "Element"
72import Text.Pandoc.Writers.Shared (metaValueToInlines)
72import Text.Pandoc.Writers.Shared (metaValueToInlines)
73import qualified Data.Map as M
73import qualified Data.Map as M
74import qualified Data.Set as S
74import qualified Data.Set as S
75−import Data.Maybe (maybeToList)
75+import Data.Maybe (maybeToList, fromMaybe)
76import Text.Pandoc.Highlighting
76import Text.Pandoc.Highlighting
77import qualified Data.Text as T
77import qualified Data.Text as T
78import Control.Applicative ((<|>))
78import Control.Applicative ((<|>))
@@ -136,7 +136,7 @@ reservedSlideIds = S.fromList [ metadataSlideId
137uniqueSlideId' :: Integer -> S.Set SlideId -> String -> SlideId
137uniqueSlideId' :: Integer -> S.Set SlideId -> String -> SlideId
138uniqueSlideId' n idSet s =
138uniqueSlideId' n idSet s =
139− let s' = if n == 0 then s else (s ++ "-" ++ show n)
139+ let s' = if n == 0 then s else s ++ "-" ++ show n
140 in if SlideId s' `S.member` idSet
140 in if SlideId s' `S.member` idSet
141 then uniqueSlideId' (n+1) idSet s
141 then uniqueSlideId' (n+1) idSet s
142 else SlideId s'
142 else SlideId s'
@@ -152,7 +152,7 @@ runUniqueSlideId s = do
152 return sldId
152 return sldId
154addLogMessage :: LogMessage -> Pres ()
154addLogMessage :: LogMessage -> Pres ()
155−addLogMessage msg = modify $ \st -> st{stLog = msg : (stLog st)}
155+addLogMessage msg = modify $ \st -> st{stLog = msg : stLog st}
157type Pres = ReaderT WriterEnv (State WriterState)
157type Pres = ReaderT WriterEnv (State WriterState)
@@ -180,7 +180,7 @@ data DocProps = DocProps { dcTitle :: Maybe String
181data Slide = Slide { slideId :: SlideId
181data Slide = Slide { slideId :: SlideId
182 , slideLayout :: Layout
182 , slideLayout :: Layout
183− , slideNotes :: (Maybe Notes)
183+ , slideNotes :: Maybe Notes
184 } deriving (Show, Eq)
184 } deriving (Show, Eq)
186newtype SlideId = SlideId String
186newtype SlideId = SlideId String
@@ -345,12 +345,12 @@ inlineToParElems (SmallCaps ils) =
345inlineToParElems Space = inlineToParElems (Str " ")
345inlineToParElems Space = inlineToParElems (Str " ")
346inlineToParElems SoftBreak = inlineToParElems (Str " ")
346inlineToParElems SoftBreak = inlineToParElems (Str " ")
347inlineToParElems LineBreak = return [Break]
347inlineToParElems LineBreak = return [Break]
348−inlineToParElems (Link _ ils (url, title)) = do
348+inlineToParElems (Link _ ils (url, title)) =
349 local (\r ->r{envRunProps = (envRunProps r){rLink = Just $ ExternalTarget (url, title)}}) $
349 local (\r ->r{envRunProps = (envRunProps r){rLink = Just $ ExternalTarget (url, title)}}) $
350− inlinesToParElems ils
350+ inlinesToParElems ils
351−inlineToParElems (Code _ str) = do
351+inlineToParElems (Code _ str) =
352 local (\r ->r{envRunProps = (envRunProps r){rPropCode = True}}) $
352 local (\r ->r{envRunProps = (envRunProps r){rPropCode = True}}) $
353− inlineToParElems $ Str str
353+ inlineToParElems $ Str str
354inlineToParElems (Math mathtype str) =
354inlineToParElems (Math mathtype str) =
355 return [MathElem mathtype (TeXString str)]
355 return [MathElem mathtype (TeXString str)]
356inlineToParElems (Note blks) = do
356inlineToParElems (Note blks) = do
@@ -409,7 +409,7 @@ blockToParagraphs (CodeBlock attr str) =
409 Just sty ->
409 Just sty ->
410 case highlight synMap (formatSourceLines sty) attr str of
410 case highlight synMap (formatSourceLines sty) attr str of
411 Right pElems -> do pProps <- asks envParaProps
411 Right pElems -> do pProps <- asks envParaProps
412− return $ [Paragraph pProps pElems]
412+ return [Paragraph pProps pElems]
413 Left _ -> blockToParagraphs $ Para [Str str]
413 Left _ -> blockToParagraphs $ Para [Str str]
414 Nothing -> blockToParagraphs $ Para [Str str]
414 Nothing -> blockToParagraphs $ Para [Str str]
415-- We can't yet do incremental lists, but we should render a
415-- We can't yet do incremental lists, but we should render a
@@ -463,7 +463,7 @@ blockToParagraphs (DefinitionList entries) = do
463 definition <- concatMapM (blockToParagraphs . BlockQuote) blksLst
463 definition <- concatMapM (blockToParagraphs . BlockQuote) blksLst
464 return $ term ++ definition
464 return $ term ++ definition
465 concatMapM go entries
465 concatMapM go entries
466−blockToParagraphs (Div (_, ("notes" : []), _) _) = return []
466+blockToParagraphs (Div (_, "notes" : [], _) _) = return []
467blockToParagraphs (Div _ blks) = concatMapM blockToParagraphs blks
467blockToParagraphs (Div _ blks) = concatMapM blockToParagraphs blks
468blockToParagraphs blk = do
468blockToParagraphs blk = do
469 addLogMessage $ BlockNotRendered blk
469 addLogMessage $ BlockNotRendered blk
@@ -481,7 +481,7 @@ multiParBullet (b:bs) = do
482cellToParagraphs :: Alignment -> TableCell -> Pres [Paragraph]
482cellToParagraphs :: Alignment -> TableCell -> Pres [Paragraph]
483cellToParagraphs algn tblCell = do
483cellToParagraphs algn tblCell = do
484− paras <- mapM (blockToParagraphs) tblCell
484+ paras <- mapM blockToParagraphs tblCell
485 let alignment = case algn of
485 let alignment = case algn of
486 AlignLeft -> Just AlgnLeft
486 AlignLeft -> Just AlgnLeft
487 AlignRight -> Just AlgnRight
487 AlignRight -> Just AlgnRight
@@ -494,7 +494,7 @@ rowToParagraphs :: [Alignment] -> [TableCell] -> Pres [[Paragraph]]
494rowToParagraphs algns tblCells = do
494rowToParagraphs algns tblCells = do
495 -- We have to make sure we have the right number of alignments
495 -- We have to make sure we have the right number of alignments
496 let pairs = zip (algns ++ repeat AlignDefault) tblCells
496 let pairs = zip (algns ++ repeat AlignDefault) tblCells
497− mapM (\(a, tc) -> cellToParagraphs a tc) pairs
497+ mapM (uncurry cellToParagraphs) pairs
499withAttr :: Attr -> Shape -> Shape
499withAttr :: Attr -> Shape -> Shape
500withAttr attr (Pic picPr url caption) =
500withAttr attr (Pic picPr url caption) =
@@ -507,17 +507,17 @@ withAttr _ sp = sp
508blockToShape :: Block -> Pres Shape
508blockToShape :: Block -> Pres Shape
509blockToShape (Plain (il:_)) | Image attr ils (url, _) <- il =
509blockToShape (Plain (il:_)) | Image attr ils (url, _) <- il =
510− (withAttr attr . Pic def url) <$> (inlinesToParElems ils)
510+ (withAttr attr . Pic def url) <$> inlinesToParElems ils
511blockToShape (Para (il:_)) | Image attr ils (url, _) <- il =
511blockToShape (Para (il:_)) | Image attr ils (url, _) <- il =
512− (withAttr attr . Pic def url) <$> (inlinesToParElems ils)
512+ (withAttr attr . Pic def url) <$> inlinesToParElems ils
513blockToShape (Plain (il:_)) | Link _ (il':_) target <- il
513blockToShape (Plain (il:_)) | Link _ (il':_) target <- il
514 , Image attr ils (url, _) <- il' =
514 , Image attr ils (url, _) <- il' =
515 (withAttr attr . Pic def {picPropLink = Just $ ExternalTarget target} url) <$>
515 (withAttr attr . Pic def {picPropLink = Just $ ExternalTarget target} url) <$>
516− (inlinesToParElems ils)
516+ inlinesToParElems ils
517blockToShape (Para (il:_)) | Link _ (il':_) target <- il
517blockToShape (Para (il:_)) | Link _ (il':_) target <- il
518 , Image attr ils (url, _) <- il' =
518 , Image attr ils (url, _) <- il' =
519 (withAttr attr . Pic def{picPropLink = Just $ ExternalTarget target} url) <$>
519 (withAttr attr . Pic def{picPropLink = Just $ ExternalTarget target} url) <$>
520− (inlinesToParElems ils)
520+ inlinesToParElems ils
521blockToShape (Table caption algn _ hdrCells rows) = do
521blockToShape (Table caption algn _ hdrCells rows) = do
522 caption' <- inlinesToParElems caption
522 caption' <- inlinesToParElems caption
523 hdrCells' <- rowToParagraphs algn hdrCells
523 hdrCells' <- rowToParagraphs algn hdrCells
@@ -537,11 +537,11 @@ blockToShape blk = do paras <- blockToParagraphs blk
538combineShapes :: [Shape] -> [Shape]
538combineShapes :: [Shape] -> [Shape]
539combineShapes [] = []
539combineShapes [] = []
540−combineShapes (s : []) = [s]
540+combineShapes[s] = [s]
541−combineShapes (pic@(Pic _ _ _) : ss) = pic : combineShapes ss
541+combineShapes (pic@(Pic{}) : ss) = pic : combineShapes ss
542−combineShapes ((TextBox []) : ss) = combineShapes ss
542+combineShapes (TextBox [] : ss) = combineShapes ss
543combineShapes (s : TextBox [] : ss) = combineShapes (s : ss)
543combineShapes (s : TextBox [] : ss) = combineShapes (s : ss)
544−combineShapes ((TextBox (p:ps)) : (TextBox (p':ps')) : ss) =
544+combineShapes (TextBox (p:ps) : TextBox (p':ps') : ss) =
545 combineShapes $ TextBox ((p:ps) ++ (p':ps')) : ss
545 combineShapes $ TextBox ((p:ps) ++ (p':ps')) : ss
546combineShapes (s:ss) = s : combineShapes ss
546combineShapes (s:ss) = s : combineShapes ss
@@ -549,8 +549,8 @@ blocksToShapes :: [Block] -> Pres [Shape]
549blocksToShapes blks = combineShapes <$> mapM blockToShape blks
549blocksToShapes blks = combineShapes <$> mapM blockToShape blks
551isImage :: Inline -> Bool
551isImage :: Inline -> Bool
552−isImage (Image _ _ _) = True
552+isImage (Image{}) = True
553−isImage (Link _ ((Image _ _ _) : _) _) = True
553+isImage (Link _ (Image _ _ _ : _) _) = True
554isImage _ = False
554isImage _ = False
556splitBlocks' :: [Block] -> [[Block]] -> [Block] -> Pres [[Block]]
556splitBlocks' :: [Block] -> [[Block]] -> [Block] -> Pres [[Block]]
@@ -565,27 +565,27 @@ splitBlocks' cur acc (h@(Header n _ _) : blks) = do
565 GT -> splitBlocks' (cur ++ [h]) acc blks
565 GT -> splitBlocks' (cur ++ [h]) acc blks
566-- `blockToParagraphs` treats Plain and Para the same, so we can save
566-- `blockToParagraphs` treats Plain and Para the same, so we can save
567-- some code duplication by treating them the same here.
567-- some code duplication by treating them the same here.
568−splitBlocks' cur acc ((Plain ils) : blks) = splitBlocks' cur acc ((Para ils) : blks)
568+splitBlocks' cur acc (Plain ils : blks) = splitBlocks' cur acc (Para ils : blks)
569−splitBlocks' cur acc ((Para (il:ils)) : blks) | isImage il = do
569+splitBlocks' cur acc (Para (il:ils) : blks) | isImage il = do
570 slideLevel <- asks envSlideLevel
570 slideLevel <- asks envSlideLevel
571 case cur of
571 case cur of
572− (Header n _ _) : [] | n == slideLevel ->
572+ [(Header n _ _)] | n == slideLevel ->
573 splitBlocks' []
573 splitBlocks' []
574 (acc ++ [cur ++ [Para [il]]])
574 (acc ++ [cur ++ [Para [il]]])
575− (if null ils then blks else (Para ils) : blks)
575+ (if null ils then blks else Para ils : blks)
576 _ -> splitBlocks' []
576 _ -> splitBlocks' []
577 (acc ++ (if null cur then [] else [cur]) ++ [[Para [il]]])
577 (acc ++ (if null cur then [] else [cur]) ++ [[Para [il]]])
578− (if null ils then blks else (Para ils) : blks)
578+ (if null ils then blks else Para ils : blks)
579−splitBlocks' cur acc (tbl@(Table _ _ _ _ _) : blks) = do
579+splitBlocks' cur acc (tbl@(Table{}) : blks) = do
580 slideLevel <- asks envSlideLevel
580 slideLevel <- asks envSlideLevel
581 case cur of
581 case cur of
582− (Header n _ _) : [] | n == slideLevel ->
582+ [(Header n _ _)] | n == slideLevel ->
583 splitBlocks' [] (acc ++ [cur ++ [tbl]]) blks
583 splitBlocks' [] (acc ++ [cur ++ [tbl]]) blks
584 _ -> splitBlocks' [] (acc ++ (if null cur then [] else [cur]) ++ [[tbl]]) blks
584 _ -> splitBlocks' [] (acc ++ (if null cur then [] else [cur]) ++ [[tbl]]) blks
585splitBlocks' cur acc (d@(Div (_, classes, _) _): blks) | "columns" `elem` classes = do
585splitBlocks' cur acc (d@(Div (_, classes, _) _): blks) | "columns" `elem` classes = do
586 slideLevel <- asks envSlideLevel
586 slideLevel <- asks envSlideLevel
587 case cur of
587 case cur of
588− (Header n _ _) : [] | n == slideLevel ->
588+ [(Header n _ _)] | n == slideLevel ->
589 splitBlocks' [] (acc ++ [cur ++ [d]]) blks
589 splitBlocks' [] (acc ++ [cur ++ [d]]) blks
590 _ -> splitBlocks' [] (acc ++ (if null cur then [] else [cur]) ++ [[d]]) blks
590 _ -> splitBlocks' [] (acc ++ (if null cur then [] else [cur]) ++ [[d]]) blks
591splitBlocks' cur acc (blk : blks) = splitBlocks' (cur ++ [blk]) acc blks
591splitBlocks' cur acc (blk : blks) = splitBlocks' (cur ++ [blk]) acc blks
@@ -594,12 +594,12 @@ splitBlocks :: [Block] -> Pres [[Block]]
594splitBlocks = splitBlocks' [] []
594splitBlocks = splitBlocks' [] []
596blocksToSlide' :: Int -> [Block] -> Pres Slide
596blocksToSlide' :: Int -> [Block] -> Pres Slide
597−blocksToSlide' lvl ((Header n (ident, _, _) ils) : blks)
597+blocksToSlide' lvl (Header n (ident, _, _) ils : blks)
598 | n < lvl = do
598 | n < lvl = do
599 registerAnchorId ident
599 registerAnchorId ident
600 sldId <- asks envCurSlideId
600 sldId <- asks envCurSlideId
601 hdr <- inlinesToParElems ils
601 hdr <- inlinesToParElems ils
602− return $ Slide sldId (TitleSlide {titleSlideHeader = hdr}) Nothing
602+ return $ Slide sldId TitleSlide {titleSlideHeader = hdr} Nothing
603 | n == lvl = do
603 | n == lvl = do
604 registerAnchorId ident
604 registerAnchorId ident
605 hdr <- inlinesToParElems ils
605 hdr <- inlinesToParElems ils
@@ -614,7 +614,7 @@ blocksToSlide' lvl ((Header n (ident, _, _) ils) : blks)
614blocksToSlide' _ (blk : blks)
614blocksToSlide' _ (blk : blks)
615 | Div (_, classes, _) divBlks <- blk
615 | Div (_, classes, _) divBlks <- blk
616 , "columns" `elem` classes
616 , "columns" `elem` classes
617− , (Div (_, clsL, _) blksL) : (Div (_, clsR, _) blksR) : remaining <- divBlks
617+ , Div (_, clsL, _) blksL : Div (_, clsR, _) blksR : remaining <- divBlks
618 , "column" `elem` clsL, "column" `elem` clsR = do
618 , "column" `elem` clsL, "column" `elem` clsR = do
619 unless (null blks)
619 unless (null blks)
620 (mapM (addLogMessage . BlockNotRendered) blks >> return ())
620 (mapM (addLogMessage . BlockNotRendered) blks >> return ())
@@ -672,7 +672,7 @@ makeNoteEntry n blks =
673 case blks of
673 case blks of
674 (Para ils : blks') -> (Para $ enum : Space : ils) : blks'
674 (Para ils : blks') -> (Para $ enum : Space : ils) : blks'
675− _ -> (Para [enum]) : blks
675+ _ -> Para [enum] : blks
677forceFontSize :: Pixels -> Pres a -> Pres a
677forceFontSize :: Pixels -> Pres a -> Pres a
678forceFontSize px x = do
678forceFontSize px x = do
@@ -860,7 +860,7 @@ blocksToPresentationSlides blks = do
860 (\env -> env { envCurSlideId = endNotesSlideId
860 (\env -> env { envCurSlideId = endNotesSlideId
861 , envInNoteSlide = True
861 , envInNoteSlide = True
863− (blocksToSlide $ endNotesSlideBlocks)
863+ (blocksToSlide endNotesSlideBlocks)
864 return [endNotesSlide]
864 return [endNotesSlide]
866 let slides = metadataslides ++ tocSlides ++ bodyslides ++ endNotesSlides
866 let slides = metadataslides ++ tocSlides ++ bodyslides ++ endNotesSlides
@@ -889,9 +889,7 @@ documentToPresentation :: WriterOptions
889documentToPresentation opts (Pandoc meta blks) =
889documentToPresentation opts (Pandoc meta blks) =
890 let env = def { envOpts = opts
890 let env = def { envOpts = opts
891 , envMetadata = meta
891 , envMetadata = meta
892− , envSlideLevel = case writerSlideLevel opts of
892+ , envSlideLevel = fromMaybe (getSlideLevel blks) (writerSlideLevel opts)
894− Nothing -> getSlideLevel blks
896 (presSlides, msgs) = runPres env def $ blocksToPresentationSlides blks
894 (presSlides, msgs) = runPres env def $ blocksToPresentationSlides blks
897 docProps = metaToDocProps meta
895 docProps = metaToDocProps meta