module Text.Pandoc.Writers.Markdown.Types (
MarkdownVariant(..),
WriterState(..),
WriterEnv(..),
Notes,
Ref,
Refs,
MD,
evalMD
) where
import Control.Monad.Reader
import Control.Monad.State.Strict
import Data.Default
import qualified Data.Map as M
import qualified Data.Set as Set
import Data.Text (Text)
import Text.Pandoc.Parsing (Key)
import Text.Pandoc.Class.PandocMonad (PandocMonad)
import Text.Pandoc.Definition
type Notes = [[Block]]
type Ref = (Text, Target, Attr)
type Refs = [Ref]
type MD m = ReaderT WriterEnv (StateT WriterState m)
evalMD :: PandocMonad m => MD m a -> WriterEnv -> WriterState -> m a
evalMD :: forall (m :: * -> *) a.
PandocMonad m =>
MD m a -> WriterEnv -> WriterState -> m a
evalMD MD m a
md WriterEnv
env WriterState
st = StateT WriterState m a -> WriterState -> m a
forall (m :: * -> *) s a. Monad m => StateT s m a -> s -> m a
evalStateT (MD m a -> WriterEnv -> StateT WriterState m a
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT MD m a
md WriterEnv
env) WriterState
st
data WriterEnv = WriterEnv { WriterEnv -> Bool
envInList :: Bool
, WriterEnv -> MarkdownVariant
envVariant :: MarkdownVariant
, WriterEnv -> Bool
envRefShortcutable :: Bool
, WriterEnv -> Int
envBlockLevel :: Int
, WriterEnv -> Bool
envEscapeSpaces :: Bool
}
data MarkdownVariant =
Markua
| PlainText
| Commonmark
| Markdown
deriving (Int -> MarkdownVariant -> ShowS
[MarkdownVariant] -> ShowS
MarkdownVariant -> String
(Int -> MarkdownVariant -> ShowS)
-> (MarkdownVariant -> String)
-> ([MarkdownVariant] -> ShowS)
-> Show MarkdownVariant
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MarkdownVariant -> ShowS
showsPrec :: Int -> MarkdownVariant -> ShowS
$cshow :: MarkdownVariant -> String
show :: MarkdownVariant -> String
$cshowList :: [MarkdownVariant] -> ShowS
showList :: [MarkdownVariant] -> ShowS
Show, MarkdownVariant -> MarkdownVariant -> Bool
(MarkdownVariant -> MarkdownVariant -> Bool)
-> (MarkdownVariant -> MarkdownVariant -> Bool)
-> Eq MarkdownVariant
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MarkdownVariant -> MarkdownVariant -> Bool
== :: MarkdownVariant -> MarkdownVariant -> Bool
$c/= :: MarkdownVariant -> MarkdownVariant -> Bool
/= :: MarkdownVariant -> MarkdownVariant -> Bool
Eq)
instance Default WriterEnv
where def :: WriterEnv
def = WriterEnv { envInList :: Bool
envInList = Bool
False
, envVariant :: MarkdownVariant
envVariant = MarkdownVariant
Markdown
, envRefShortcutable :: Bool
envRefShortcutable = Bool
True
, envBlockLevel :: Int
envBlockLevel = Int
0
, envEscapeSpaces :: Bool
envEscapeSpaces = Bool
False
}
data WriterState = WriterState { WriterState -> Notes
stNotes :: Notes
, WriterState -> Refs
stPrevRefs :: Refs
, WriterState -> Refs
stRefs :: Refs
, WriterState -> Map Key (Map (Target, Attr) Int)
stKeys :: M.Map Key
(M.Map (Target, Attr) Int)
, WriterState -> Int
stLastIdx :: Int
, WriterState -> Set Text
stIds :: Set.Set Text
, WriterState -> Int
stNoteNum :: Int
}
instance Default WriterState
where def :: WriterState
def = WriterState{ stNotes :: Notes
stNotes = []
, stPrevRefs :: Refs
stPrevRefs = []
, stRefs :: Refs
stRefs = []
, stKeys :: Map Key (Map (Target, Attr) Int)
stKeys = Map Key (Map (Target, Attr) Int)
forall k a. Map k a
M.empty
, stLastIdx :: Int
stLastIdx = Int
0
, stIds :: Set Text
stIds = Set Text
forall a. Set a
Set.empty
, stNoteNum :: Int
stNoteNum = Int
1
}