{-# LINE 1 "src/Text/Sundown/Foreign.hsc" #-}
{-# Language EmptyDataDecls #-}
{-# Language ForeignFunctionInterface #-}
module Text.Sundown.Foreign
    ( Extensions (..)
    , noExtensions
    , allExtensions
    , Callbacks
    , sd_markdown_new
    , sd_markdown_render
    , sd_markdown_free
    ) where

import Foreign
import Foreign.C.String
import Foreign.C.Types

import Text.Sundown.Buffer.Foreign
import Text.Sundown.Flag



-- | A set of switches to enable or disable markdown features.
data Extensions = Extensions
    { Extensions -> Bool
extNoIntraEmphasis :: Bool
      -- ^ Turn off underscores insode a word does designating emphasis.
    , Extensions -> Bool
extTables          :: Bool
    , Extensions -> Bool
extFencedCode      :: Bool
    -- ^ Turns on a non-indentation form of code-blocks, by blocking off a
    --   regionwith ~ or \`.
    , Extensions -> Bool
extAutolink        :: Bool
    -- ^ Turn things that look like URLs and email addresses into links
    , Extensions -> Bool
extStrikethrough   :: Bool
    -- ^ Surround text with `~` to designate it as struck through
    , Extensions -> Bool
extSpaceHeaders    :: Bool
    , Extensions -> Bool
extSuperscript     :: Bool
    , Extensions -> Bool
extLaxSpacing      :: Bool
    -- ^ Allow blocks inside of paragraphs, instead requireing tags to be on
    --   separate lines
    }

-- | All 'Extensions' disabled
noExtensions :: Extensions
noExtensions :: Extensions
noExtensions = Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Extensions
Extensions Bool
False Bool
False Bool
False Bool
False Bool
False Bool
False Bool
False Bool
False

-- | All 'Extensions' enabled
allExtensions :: Extensions
allExtensions :: Extensions
allExtensions = Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Bool
-> Extensions
Extensions Bool
True Bool
True Bool
True Bool
True Bool
True Bool
True Bool
True Bool
True

instance Flag Extensions where
    flagIndexes :: Extensions -> [(CUInt, Bool)]
flagIndexes Extensions
exts =
        [ (CUInt
1, Extensions -> Bool
extNoIntraEmphasis Extensions
exts)
{-# LINE 52 "src/Text/Sundown/Foreign.hsc" #-}
        , (CUInt
2,            Extensions -> Bool
extTables Extensions
exts)
{-# LINE 53 "src/Text/Sundown/Foreign.hsc" #-}
        , (CUInt
4,       Extensions -> Bool
extFencedCode Extensions
exts)
{-# LINE 54 "src/Text/Sundown/Foreign.hsc" #-}
        , (CUInt
8,          Extensions -> Bool
extAutolink Extensions
exts)
{-# LINE 55 "src/Text/Sundown/Foreign.hsc" #-}
        , (CUInt
16,     Extensions -> Bool
extStrikethrough Extensions
exts)
{-# LINE 56 "src/Text/Sundown/Foreign.hsc" #-}
        , (CUInt
64,     Extensions -> Bool
extSpaceHeaders Extensions
exts)
{-# LINE 57 "src/Text/Sundown/Foreign.hsc" #-}
        , (CUInt
128,       Extensions -> Bool
extSuperscript Extensions
exts)
{-# LINE 58 "src/Text/Sundown/Foreign.hsc" #-}
        , (CUInt
256,       Extensions -> Bool
extLaxSpacing Extensions
exts)
{-# LINE 59 "src/Text/Sundown/Foreign.hsc" #-}
        ]

data Callbacks

instance Storable Callbacks where
    sizeOf :: Callbacks -> Int
sizeOf Callbacks
_    = (Int
208)
{-# LINE 65 "src/Text/Sundown/Foreign.hsc" #-}
    alignment _ = alignment (undefined :: Ptr ())
    peek :: Ptr Callbacks -> IO Callbacks
peek Ptr Callbacks
_      = [Char] -> IO Callbacks
forall a. HasCallStack => [Char] -> a
error [Char]
"Callbacks.peek is not implemented"
    poke :: Ptr Callbacks -> Callbacks -> IO ()
poke Ptr Callbacks
_ Callbacks
_    = [Char] -> IO ()
forall a. HasCallStack => [Char] -> a
error [Char]
"Callbacks.poke is not implemented"

data Markdown

instance Storable Markdown where
    sizeOf :: Markdown -> Int
sizeOf Markdown
_    = [Char] -> Int
forall a. HasCallStack => [Char] -> a
error [Char]
"Markdown.sizeOf is not implemented"
    alignment :: Markdown -> Int
alignment Markdown
_ = Ptr () -> Int
forall a. Storable a => a -> Int
alignment (Ptr ()
forall a. HasCallStack => a
undefined :: Ptr ())
    peek :: Ptr Markdown -> IO Markdown
peek Ptr Markdown
_      = [Char] -> IO Markdown
forall a. HasCallStack => [Char] -> a
error [Char]
"Markdown.peek is not implemented"
    poke :: Ptr Markdown -> Markdown -> IO ()
poke Ptr Markdown
_      = [Char] -> Markdown -> IO ()
forall a. HasCallStack => [Char] -> a
error [Char]
"Markdown.poke is not implemented"

sd_markdown_new
    :: Extensions -> CSize -> Ptr Callbacks -> Ptr () -> IO (Ptr Markdown)
sd_markdown_new :: Extensions -> CSize -> Ptr Callbacks -> Ptr () -> IO (Ptr Markdown)
sd_markdown_new Extensions
extensions CSize
max_nesting Ptr Callbacks
callbacks Ptr ()
opaque =
    CUInt -> CSize -> Ptr Callbacks -> Ptr () -> IO (Ptr Markdown)
sd_markdown_new' (Extensions -> CUInt
forall a. Flag a => a -> CUInt
toCUInt Extensions
extensions) CSize
max_nesting Ptr Callbacks
callbacks Ptr ()
opaque
foreign import ccall "markdown.h sd_markdown_new"
    sd_markdown_new'
        :: CUInt -> CSize -> Ptr Callbacks -> Ptr () -> IO (Ptr Markdown)

foreign import ccall "markdown.h sd_markdown_render"
    sd_markdown_render
        :: Ptr Buffer -> CString -> CSize -> Ptr Markdown -> IO ()

foreign import ccall "markdown.h sd_markdown_free"
    sd_markdown_free :: Ptr Markdown -> IO ()