module Slides.Common
( Eagerness(..), Presentation(..), Slide(..), ContentNode(..), Style(..)
, Selector(..), ElementStyle(..), emptyPresentation, emptyStyle, emptyElementStyle
) where
import Diagrams (Diagram)
import Diagrams.Backend.SVG (SVG(..))
import Data.Colour (Colour)
import Data.FileEmbed
import Data.String (IsString(..))
import Text.Regex.Applicative (replace, few, anySym)
data Eagerness
= Delay
| Immediate
deriving (Eq, Show)
data Presentation = Presentation { slides :: [Slide]
, style :: Style
, baseHead :: String }
newtype Slide = Slide { nodes :: [ContentNode] }
data ContentNode
= Header Int String
| List [ContentNode]
| Text String
| Break
| RawSVG Int Int String
| Diagram Int (Diagram SVG)
| UnfoldList Eagerness [ContentNode]
| Sequence Eagerness [ContentNode]
| ConcatList [ContentNode]
| UnfoldConcatList Eagerness [ContentNode]
data Style = Style
{
selectors :: [(Selector, ElementStyle)]
, baseCss :: String }
deriving (Eq, Show, Read)
data Selector
= HeaderSelector Int
| UniversalSelector
| TextSelector
| SlideSelector
deriving (Eq, Ord, Show, Read)
data ElementStyle = ElementStyle { backgroundColor :: Maybe (Colour Float)
, fontFamily :: Maybe String
, fontSize :: Maybe Int }
deriving (Eq, Show, Read)
emptyPresentation :: Presentation
emptyPresentation = Presentation [] emptyStyle "<meta charset=\"utf-8\" />"
emptyStyle :: Style
emptyStyle = Style [] $(embedStringFile "assets/default.css")
emptyElementStyle :: ElementStyle
emptyElementStyle = ElementStyle Nothing Nothing Nothing
wrapIn :: String -> String -> String
wrapIn tag str = "<" ++ tag ++ ">" ++ str ++ "</" ++ tag ++ ">"
inlineMarkdown :: String -> ContentNode
inlineMarkdown = Text . replace (wrapIn "i" <$> ("*" *> few anySym <* "*"))
. replace (wrapIn "i" <$> ("_" *> few anySym <* "_"))
. replace (wrapIn "b" <$> ("**" *> few anySym <* "**"))
. replace (wrapIn "b" <$> ("__" *> few anySym <* "__"))
instance IsString ContentNode where
fromString = inlineMarkdown