1{-# LANGUAGE DeriveDataTypeable #-}
2module Cheapskate.Types where
3import Data.Sequence (Seq)
4import Data.Text (Text)
5import qualified Data.Map as M
6import Data.Data
7
8-- | Structured representation of a document.  The 'Options' affect
9-- how the document is rendered by `toHtml`.
10data Doc = Doc Options Blocks
11           deriving (Show, Data, Typeable)
12
13-- | Block-level elements.
14data Block = Para Inlines
15           | Header Int Inlines
16           | Blockquote Blocks
17           | List Bool ListType [Blocks]
18           | CodeBlock CodeAttr Text
19           | HtmlBlock Text
20           | HRule
21           | ReferencesBlock [(Text, Text, Text)]
22           | ElmDocs [[Text]]
23           deriving (Show, Data, Typeable, Eq)
24
25-- | Attributes for fenced code blocks.  'codeLang' is the
26-- first word of the attribute line, 'codeInfo' is the rest.
27data CodeAttr = CodeAttr { codeLang :: Text, codeInfo :: Text }
28              deriving (Show, Data, Typeable, Eq)
29
30data ListType = Bullet Char | Numbered NumWrapper Int deriving (Eq,Show,Data,Typeable)
31data NumWrapper = PeriodFollowing | ParenFollowing deriving (Eq,Show,Data,Typeable)
32
33-- | Simple representation of HTML tag.
34data HtmlTagType = Opening Text | Closing Text | SelfClosing Text deriving (Show, Data, Typeable)
35
36-- We operate with sequences instead of lists, because
37-- they allow more efficient appending on to the end.
38type Blocks = Seq Block
39
40-- | Inline elements.
41data Inline = Str Text
42            | Space
43            | SoftBreak
44            | LineBreak
45            | Emph Inlines
46            | Strong Inlines
47            | Code Text
48            | Link Inlines LinkTarget {- URL -} Text {- title -}
49            | Image Inlines Text {- URL -} Text {- title -}
50            | Entity Text
51            | RawHtml Text
52            deriving (Show, Data, Typeable, Eq)
53
54
55data LinkTarget
56    = Url Text
57    | Ref Text
58    deriving (Show, Data, Eq)
59
60
61type Inlines = Seq Inline
62
63type ReferenceMap = M.Map Text (Text, Text)
64
65-- | Rendering and parsing options.
66data Options = Options{
67    sanitize           :: Bool  -- ^ Sanitize raw HTML, link/image attributes
68  , allowRawHtml       :: Bool  -- ^ Allow raw HTML (if false it gets escaped)
69  , preserveHardBreaks :: Bool  -- ^ Preserve hard line breaks in the source
70  , debug              :: Bool  -- ^ Print container structure for debugging
71  }
72  deriving (Show, Data, Typeable)
73