Commit f09db6b7 authored by Henrik Tramberend's avatar Henrik Tramberend
Browse files

Add header with probably unique id to empty slides

parent 904023d6
......@@ -35,7 +35,7 @@ import Text.Decker.Reader.Markdown
-- import Text.Groom
import Text.Pandoc
import Text.Pandoc.Walk
import Text.Pretty.Simple
-- import Text.Pretty.Simple
compileQuestionToHtml :: Meta -> FilePath -> Question -> Action Question
compileQuestionToHtml meta base quest = do
......
......@@ -36,7 +36,7 @@ processPandoc ::
Pandoc ->
Action Pandoc
processPandoc transform base disp prov pandoc =
evalStateT (transform pandoc) (DeckerState base disp prov)
evalStateT (transform pandoc) (DeckerState base disp prov 0)
-- | Split join columns with CSS3. Must be performed after `wrapBoxes`.
splitJoinColumns :: Slide -> Decker Slide
......@@ -103,19 +103,23 @@ wrapBoxes slide@(Slide header body) = do
-- | Map over all active slides in a deck.
mapSlides :: (Slide -> Decker Slide) -> Pandoc -> Decker Pandoc
mapSlides action (Pandoc meta blocks) = do
slides <- selectActiveContent (toSlides blocks)
Pandoc meta . fromSlides <$> mapM action slides
slides <-
selectActiveContent (toSlides blocks)
>>= mapM action
>>= fromSlidesD
return $ Pandoc meta slides
filterNotebookSlides :: Pandoc -> Pandoc
filterNotebookSlides (Pandoc meta blocks) =
let inNotebook = fromSlides $ filter notebook (toSlides blocks)
let notebook slide = "notebook" `elem` view (attributes . attrClasses) slide
inNotebook = fromSlides $ filter notebook (toSlides blocks)
stripped = walk strip inNotebook
strip (Header level _ inlines) = Header level nullAttr inlines
strip (CodeBlock (_, classes, _) code)
| "code" `notElem` classes = CodeBlock nullAttr code
strip block = block
notebook slide = "notebook" `elem` (view (attributes . attrClasses) slide)
in Pandoc meta (deDiv stripped)
where
strip (Header level _ inlines) = Header level nullAttr inlines
strip (CodeBlock (_, classes, _) code)
| "code" `notElem` classes = CodeBlock nullAttr code
strip block = block
wrapSlidesinDivs :: Pandoc -> Pandoc
wrapSlidesinDivs (Pandoc meta blocks) =
......
......@@ -17,14 +17,18 @@ module Text.Decker.Filter.Slide
header,
isBoxDelim,
toSlides,
fromSlidesD,
)
where
import Control.Lens
import Control.Monad.State (gets, modify)
import Data.List
import Data.List.Split
import Data.Maybe
import Data.Text (Text)
import qualified Data.Text as Text
import Text.Decker.Internal.Common (Decker, DeckerState (emptyCount))
import Text.Pandoc
import Text.Pandoc.Definition ()
import Text.Pandoc.Lens
......@@ -90,7 +94,29 @@ fromSlides = concatMap prependHeader
++ demoteHeaders (header : body)
++ [RawBlock "html" "</aside>"]
prependHeader (Slide (Just header) body) = HorizontalRule : header : body
prependHeader (Slide Nothing body) = HorizontalRule : Header 1 nullAttr [] : body
prependHeader (Slide Nothing body) = HorizontalRule : body
fromSlidesD :: [Slide] -> Decker [Block]
fromSlidesD slides = do
concat <$> mapM prependHeader slides
where
prependHeader (Slide (Just header) body)
| hasClass "notes" header =
return $
[RawBlock "html" "<aside class=\"notes\">"]
++ demoteHeaders (header : body)
++ [RawBlock "html" "</aside>"]
prependHeader (Slide (Just header) body) = return $ HorizontalRule : header : body
prependHeader (Slide Nothing body) = do
rid <- emptyId
return $ HorizontalRule : Header 1 (rid, [], []) [] : body
emptyId :: Decker Text
emptyId = do
modify incrEmptyCount
Text.pack . ("empty-" <>) . show <$> gets emptyCount
where
incrEmptyCount s = s {emptyCount = emptyCount s + 1}
-- |  Converts slides to lists of blocks that are wrapped in divs. Used to
-- control page breaks in handout generation.
......
......@@ -16,7 +16,8 @@ doIO = lift . liftIO
data DeckerState = DeckerState
{ basePath :: String,
disposition :: Disposition,
provisioning :: Provisioning
provisioning :: Provisioning,
emptyCount :: Int
}
deriving (Eq, Show)
......
......@@ -28,9 +28,10 @@ title: Slide Separation Tests
------------------------------------------------------------------------
This is slide 4, it has no header.
This is slide 4, it has no header. But an empty header ist generated
anyways.
------------------------------------------------------------------------
This is slide 5, it also has no header.
This is slide 5, it also has no header. But an empty header ist
generated anyways.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment