-- | Definitions for creation of S5 powerpoint-like HTML. -- (See .) module Text.Pandoc.Writers.S5 ( -- * Strings s5Meta, s5Javascript, s5CSS, s5Links, -- * Functions writeS5, writeS5String, insertS5Structure ) where import Text.Pandoc.Shared ( joinWithSep, WriterOptions ) import Text.Pandoc.Writers.HTML ( writeHtml, writeHtmlString ) import Text.Pandoc.Definition import Text.XHtml.Strict s5Meta :: String s5Meta = "\n\n\n" s5Javascript :: String s5Javascript = "\n" s5CoreCSS :: String s5CoreCSS = "@s5-core.css@" s5FramingCSS :: String s5FramingCSS = "@framing.css@" s5PrettyCSS :: String s5PrettyCSS = "@pretty.css@" s5OperaCSS :: String s5OperaCSS = "@opera.css@" s5OutlineCSS :: String s5OutlineCSS = "@outline.css@" s5PrintCSS :: String s5PrintCSS = "@print.css@" s5CSS :: String s5CSS = "\n\n\n\n" s5Links :: String s5Links = "\n\n\n\n\n\n\n" -- | Converts Pandoc document to an S5 HTML presentation (Html structure). writeS5 :: WriterOptions -> Pandoc -> Html writeS5 options = (writeHtml options) . insertS5Structure -- | Converts Pandoc document to an S5 HTML presentation (string). writeS5String :: WriterOptions -> Pandoc -> String writeS5String options = (writeHtmlString options) . insertS5Structure -- | Inserts HTML needed for an S5 presentation (e.g. around slides). layoutDiv :: [Inline] -- ^ Title of document (for header or footer) -> String -- ^ Date of document (for header or footer) -> [Block] -- ^ List of block elements returned layoutDiv title date = [(RawHtml "
\n
\n
\n
\n
\n"), (Header 1 [Str date]), (Header 2 title), (RawHtml "
\n
\n")] presentationStart = (RawHtml "
\n\n") presentationEnd = (RawHtml "
\n") slideStart = (RawHtml "
\n") slideEnd = (RawHtml "
\n") -- | Returns 'True' if block is a Header 1. isH1 :: Block -> Bool isH1 (Header 1 _) = True isH1 _ = False -- | Insert HTML around sections to make individual slides. insertSlides :: Bool -> [Block] -> [Block] insertSlides beginning blocks = let (beforeHead, rest) = break isH1 blocks in if (null rest) then if beginning then beforeHead else beforeHead ++ [slideEnd] else if beginning then beforeHead ++ slideStart:(head rest):(insertSlides False (tail rest)) else beforeHead ++ slideEnd:slideStart:(head rest):(insertSlides False (tail rest)) -- | Insert blocks into 'Pandoc' for slide structure. insertS5Structure :: Pandoc -> Pandoc insertS5Structure (Pandoc meta []) = Pandoc meta [] insertS5Structure (Pandoc (Meta title authors date) blocks) = let slides = insertSlides True blocks firstSlide = if (not (null title)) then [slideStart, (Header 1 title), (Header 3 [Str (joinWithSep ", " authors)]), (Header 4 [Str date]), slideEnd] else [] in let newBlocks = (layoutDiv title date) ++ presentationStart:firstSlide ++ slides ++ [presentationEnd] in Pandoc (Meta title authors date) newBlocks