{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Text.Pandoc.Readers.Typst
( readTypst
)
where
import Text.Pandoc.Class
import Text.Pandoc.Sources
import Text.Pandoc.Options
import Text.Pandoc.Definition
import Typst ( parseTypst, evaluateTypst )
import Text.Pandoc.Error (PandocError(..))
import Text.Pandoc.Shared (tshow, blocksToInlines)
import Control.Monad.Except (throwError)
import Control.Monad (MonadPlus (mplus), void, mzero)
import qualified Data.Foldable as F
import qualified Data.Map as M
import Data.Maybe (catMaybes, fromMaybe)
import Data.Sequence (Seq)
import qualified Data.Sequence as Seq
import qualified Data.Set as Set
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Vector as V
import qualified Text.Pandoc.Builder as B
import Text.Pandoc.Walk
import Text.Parsec
import Text.TeXMath (writeTeX)
import Text.TeXMath.Shared (getSpaceChars)
import Text.Pandoc.Readers.Typst.Math (pMathMany)
import Text.Pandoc.Readers.Typst.Parsing (pTok, ignored, chunks, getField, P)
import Typst.Methods (formatNumber, applyPureFunction)
import Typst.Types
readTypst :: (PandocMonad m, ToSources a)
=> ReaderOptions -> a -> m Pandoc
readTypst :: forall (m :: * -> *) a.
(PandocMonad m, ToSources a) =>
ReaderOptions -> a -> m Pandoc
readTypst ReaderOptions
_opts a
inp = do
let sources :: Sources
sources = forall a. ToSources a => a -> Sources
toSources a
inp
let inputName :: SourceName
inputName = case Sources
sources of
Sources ((SourcePos
pos, Text
_):[(SourcePos, Text)]
_) -> SourcePos -> SourceName
sourceName SourcePos
pos
Sources
_ -> SourceName
""
case SourceName -> Text -> Either ParseError [Markup]
parseTypst SourceName
inputName (Sources -> Text
sourcesToText Sources
sources) of
Left ParseError
e -> forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError forall a b. (a -> b) -> a -> b
$ Text -> PandocError
PandocParseError forall a b. (a -> b) -> a -> b
$ SourceName -> Text
T.pack forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> SourceName
show ParseError
e
Right [Markup]
parsed -> do
let ops :: Operations m
ops = Operations {
loadBytes :: SourceName -> m ByteString
loadBytes = forall (m :: * -> *). PandocMonad m => SourceName -> m ByteString
readFileStrict,
currentUTCTime :: m UTCTime
currentUTCTime = forall (m :: * -> *). PandocMonad m => m UTCTime
getCurrentTime,
lookupEnvVar :: SourceName -> m (Maybe SourceName)
lookupEnvVar = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> SourceName
T.unpack) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *). PandocMonad m => Text -> m (Maybe Text)
lookupEnv forall b c a. (b -> c) -> (a -> b) -> a -> c
. SourceName -> Text
T.pack,
checkExistence :: SourceName -> m Bool
checkExistence = forall (m :: * -> *). PandocMonad m => SourceName -> m Bool
fileExists }
forall (m :: * -> *).
Monad m =>
Operations m
-> SourceName -> [Markup] -> m (Either ParseError (Seq Content))
evaluateTypst Operations m
ops SourceName
inputName [Markup]
parsed forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> PandocError
PandocParseError forall b c a. (b -> c) -> (a -> b) -> a -> c
. SourceName -> Text
T.pack forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> SourceName
show) forall (f :: * -> *) a. Applicative f => a -> f a
pure forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> u -> SourceName -> s -> m (Either ParseError a)
runParserT forall (m :: * -> *). PandocMonad m => P m Pandoc
pPandoc () SourceName
inputName forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) a. Foldable t => t a -> [a]
F.toList forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> PandocError
PandocParseError forall b c a. (b -> c) -> (a -> b) -> a -> c
. SourceName -> Text
T.pack forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> SourceName
show) forall (f :: * -> *) a. Applicative f => a -> f a
pure
pBlockElt :: PandocMonad m => P m B.Blocks
pBlockElt :: forall (m :: * -> *). PandocMonad m => P m Blocks
pBlockElt = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
Content
res <- forall (m :: * -> *).
PandocMonad m =>
(Content -> Bool) -> P m Content
pTok (\Content
t -> Content -> Bool
isBlock Content
t Bool -> Bool -> Bool
|| Bool -> Bool
not (Content -> Bool
isInline Content
t))
Maybe Text
mbident <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option forall a. Maybe a
Nothing forall a b. (a -> b) -> a -> b
$ forall a. a -> Maybe a
Just forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => P m Text
pLab
case Content
res of
Elt name :: Identifier
name@(Identifier Text
tname) Maybe SourcePos
pos Map Identifier Val
fields -> do
case forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Identifier
name forall (m :: * -> *).
PandocMonad m =>
Map Identifier (Maybe Text -> Map Identifier Val -> P m Blocks)
blockHandlers of
Maybe
(Maybe Text -> Map Identifier Val -> ParsecT [Content] () m Blocks)
Nothing -> do
forall (m :: * -> *). PandocMonad m => Text -> P m ()
ignored (Text
"unknown block element " forall a. Semigroup a => a -> a -> a
<> Text
tname forall a. Semigroup a => a -> a -> a
<>
Text
" at " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> Text
tshow Maybe SourcePos
pos)
forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Monoid a => a
mempty
Just Maybe Text -> Map Identifier Val -> ParsecT [Content] () m Blocks
handler -> Maybe Text -> Map Identifier Val -> ParsecT [Content] () m Blocks
handler Maybe Text
mbident Map Identifier Val
fields
Content
_ -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Monoid a => a
mempty
pInline :: PandocMonad m => P m B.Inlines
pInline :: forall (m :: * -> *). PandocMonad m => P m Inlines
pInline = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
Content
res <- forall (m :: * -> *).
PandocMonad m =>
(Content -> Bool) -> P m Content
pTok (\Content
t -> Content -> Bool
isInline Content
t Bool -> Bool -> Bool
|| Bool -> Bool
not (Content -> Bool
isBlock Content
t))
case Content
res of
Txt Text
t -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Text -> Inlines
B.text Text
t
Lab Text
name -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Attr -> Inlines -> Inlines
B.spanWith (Text
name, [], []) forall a. Monoid a => a
mempty
Elt (Identifier Text
tname) Maybe SourcePos
_ Map Identifier Val
_
| Text
"math." Text -> Text -> Bool
`T.isPrefixOf` Text
tname
, Text
tname forall a. Eq a => a -> a -> Bool
/= Text
"math.equation" ->
Text -> Inlines
B.math forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Exp] -> Text
writeTeX forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => Seq Content -> P m [Exp]
pMathMany (forall a. a -> Seq a
Seq.singleton Content
res)
Elt name :: Identifier
name@(Identifier Text
tname) Maybe SourcePos
pos Map Identifier Val
fields ->
case forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Identifier
name forall (m :: * -> *).
PandocMonad m =>
Map Identifier (Maybe Text -> Map Identifier Val -> P m Inlines)
inlineHandlers of
Maybe
(Maybe Text
-> Map Identifier Val -> ParsecT [Content] () m Inlines)
Nothing -> do
forall (m :: * -> *). PandocMonad m => Text -> P m ()
ignored (Text
"unknown inline element " forall a. Semigroup a => a -> a -> a
<> Text
tname forall a. Semigroup a => a -> a -> a
<>
Text
" at " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> Text
tshow Maybe SourcePos
pos)
forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Monoid a => a
mempty
Just Maybe Text -> Map Identifier Val -> ParsecT [Content] () m Inlines
handler -> Maybe Text -> Map Identifier Val -> ParsecT [Content] () m Inlines
handler forall a. Maybe a
Nothing Map Identifier Val
fields
pPandoc :: PandocMonad m => P m B.Pandoc
pPandoc :: forall (m :: * -> *). PandocMonad m => P m Pandoc
pPandoc = Blocks -> Pandoc
B.doc forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => P m Blocks
pBlocks
pBlocks :: PandocMonad m => P m B.Blocks
pBlocks :: forall (m :: * -> *). PandocMonad m => P m Blocks
pBlocks = forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many forall (m :: * -> *). PandocMonad m => P m Blocks
pBlock
pBlock :: PandocMonad m => P m B.Blocks
pBlock :: forall (m :: * -> *). PandocMonad m => P m Blocks
pBlock = forall (m :: * -> *). PandocMonad m => P m Blocks
pPara forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => P m Blocks
pBlockElt
pSpace :: PandocMonad m => P m Content
pSpace :: forall (m :: * -> *). PandocMonad m => P m Content
pSpace = forall (m :: * -> *).
PandocMonad m =>
(Content -> Bool) -> P m Content
pTok
( \case
Txt Text
t | (Char -> Bool) -> Text -> Bool
T.all (forall a. Eq a => a -> a -> Bool
== Char
' ') Text
t -> Bool
True
Content
_ -> Bool
False )
pLab :: PandocMonad m => P m Text
pLab :: forall (m :: * -> *). PandocMonad m => P m Text
pLab = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional forall (m :: * -> *). PandocMonad m => P m Content
pSpace
Lab Text
t <- forall (m :: * -> *).
PandocMonad m =>
(Content -> Bool) -> P m Content
pTok
( \case
Lab Text
_ -> Bool
True
Content
_ -> Bool
False
)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Text
t
isBlock :: Content -> Bool
isBlock :: Content -> Bool
isBlock (Elt Identifier
"raw" Maybe SourcePos
_ Map Identifier Val
fields) = forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Identifier
"block" Map Identifier Val
fields forall a. Eq a => a -> a -> Bool
== forall a. a -> Maybe a
Just (Bool -> Val
VBoolean Bool
True)
isBlock (Elt Identifier
name Maybe SourcePos
_ Map Identifier Val
_) = Identifier
name forall a. Ord a => a -> Set a -> Bool
`Set.member` Set Identifier
blockKeys
isBlock Lab{} = Bool
True
isBlock Content
_ = Bool
False
isInline :: Content -> Bool
isInline :: Content -> Bool
isInline (Elt Identifier
"raw" Maybe SourcePos
_ Map Identifier Val
fields) = forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Identifier
"block" Map Identifier Val
fields forall a. Eq a => a -> a -> Bool
/= forall a. a -> Maybe a
Just (Bool -> Val
VBoolean Bool
True)
isInline (Elt Identifier
name Maybe SourcePos
_ Map Identifier Val
_) = Identifier
name forall a. Ord a => a -> Set a -> Bool
`Set.member` Set Identifier
inlineKeys
isInline Lab{} = Bool
True
isInline Txt{} = Bool
True
blockKeys :: Set.Set Identifier
blockKeys :: Set Identifier
blockKeys = forall a. Ord a => [a] -> Set a
Set.fromList forall a b. (a -> b) -> a -> b
$ forall k a. Map k a -> [k]
M.keys
(forall (m :: * -> *).
PandocMonad m =>
Map Identifier (Maybe Text -> Map Identifier Val -> P m Blocks)
blockHandlers :: M.Map Identifier
(Maybe Text -> M.Map Identifier Val -> P PandocPure B.Blocks))
inlineKeys :: Set.Set Identifier
inlineKeys :: Set Identifier
inlineKeys = forall a. Ord a => [a] -> Set a
Set.fromList forall a b. (a -> b) -> a -> b
$ forall k a. Map k a -> [k]
M.keys
(forall (m :: * -> *).
PandocMonad m =>
Map Identifier (Maybe Text -> Map Identifier Val -> P m Inlines)
inlineHandlers :: M.Map Identifier
(Maybe Text -> M.Map Identifier Val -> P PandocPure B.Inlines))
blockHandlers :: PandocMonad m =>
M.Map Identifier
(Maybe Text -> M.Map Identifier Val -> P m B.Blocks)
blockHandlers :: forall (m :: * -> *).
PandocMonad m =>
Map Identifier (Maybe Text -> Map Identifier Val -> P m Blocks)
blockHandlers = forall k a. Ord k => [(k, a)] -> Map k a
M.fromList
[(Identifier
"text", \Maybe Text
_ Map Identifier Val
fields -> do
Seq Content
body <- forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"body" Map Identifier Val
fields
forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a. Functor f => f a -> f ()
void forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Inlines
pInlines Seq Content
body
forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Blocks
pBlocks Seq Content
body)
,(Identifier
"box", \Maybe Text
_ Map Identifier Val
fields -> do
Seq Content
body <- forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"body" Map Identifier Val
fields
Attr -> Blocks -> Blocks
B.divWith (Text
"", [Text
"box"], []) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Blocks
pBlocks Seq Content
body)
,(Identifier
"heading", \Maybe Text
mbident Map Identifier Val
fields -> do
Seq Content
body <- forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"body" Map Identifier Val
fields
Int
lev <- forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"level" Map Identifier Val
fields forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
1
Attr -> Int -> Inlines -> Blocks
B.headerWith (forall a. a -> Maybe a -> a
fromMaybe Text
"" Maybe Text
mbident,[],[]) Int
lev
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Inlines
pInlines Seq Content
body)
,(Identifier
"list", \Maybe Text
_ Map Identifier Val
fields -> do
[Seq Content]
children <- forall a. Vector a -> [a]
V.toList forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"children" Map Identifier Val
fields
[Blocks] -> Blocks
B.bulletList forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Blocks
pBlocks) [Seq Content]
children)
,(Identifier
"list.item", \Maybe Text
_ Map Identifier Val
fields -> forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"body" Map Identifier Val
fields forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Blocks
pBlocks)
,(Identifier
"enum", \Maybe Text
_ Map Identifier Val
fields -> do
[Seq Content]
children <- forall a. Vector a -> [a]
V.toList forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"children" Map Identifier Val
fields
Maybe Int
mbstart <- forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"start" Map Identifier Val
fields
Int
start <- case Maybe Int
mbstart of
Maybe Int
Nothing -> forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
1
Just Int
x
| Int
x forall a. Ord a => a -> a -> Bool
>= Int
0 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
x
| Bool
otherwise -> forall (m :: * -> *) a. MonadFail m => SourceName -> m a
fail SourceName
"number must be positive"
(Text
numbering :: Text) <- forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"numbering" Map Identifier Val
fields forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
`mplus` forall (f :: * -> *) a. Applicative f => a -> f a
pure Text
""
let (ListNumberStyle
sty, ListNumberDelim
delim) =
case Text
numbering of
Text
"1." -> (ListNumberStyle
B.Decimal, ListNumberDelim
B.Period)
Text
"1)" -> (ListNumberStyle
B.Decimal, ListNumberDelim
B.OneParen)
Text
"(1)" -> (ListNumberStyle
B.Decimal, ListNumberDelim
B.TwoParens)
Text
"a." -> (ListNumberStyle
B.LowerAlpha, ListNumberDelim
B.Period)
Text
"a)" -> (ListNumberStyle
B.LowerAlpha, ListNumberDelim
B.OneParen)
Text
"(a)" -> (ListNumberStyle
B.LowerAlpha, ListNumberDelim
B.TwoParens)
Text
"A." -> (ListNumberStyle
B.UpperAlpha, ListNumberDelim
B.Period)
Text
"A)" -> (ListNumberStyle
B.UpperAlpha, ListNumberDelim
B.OneParen)
Text
"(A)" -> (ListNumberStyle
B.UpperAlpha, ListNumberDelim
B.TwoParens)
Text
"i." -> (ListNumberStyle
B.LowerRoman, ListNumberDelim
B.Period)
Text
"i)" -> (ListNumberStyle
B.LowerRoman, ListNumberDelim
B.OneParen)
Text
"(i)" -> (ListNumberStyle
B.LowerRoman, ListNumberDelim
B.TwoParens)
Text
"I." -> (ListNumberStyle
B.UpperRoman, ListNumberDelim
B.Period)
Text
"I)" -> (ListNumberStyle
B.UpperRoman, ListNumberDelim
B.OneParen)
Text
"(I)" -> (ListNumberStyle
B.UpperRoman, ListNumberDelim
B.TwoParens)
Text
_ -> (ListNumberStyle
B.DefaultStyle, ListNumberDelim
B.DefaultDelim)
let listAttr :: (Int, ListNumberStyle, ListNumberDelim)
listAttr = (Int
start, ListNumberStyle
sty, ListNumberDelim
delim)
(Int, ListNumberStyle, ListNumberDelim) -> [Blocks] -> Blocks
B.orderedListWith (Int, ListNumberStyle, ListNumberDelim)
listAttr forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Blocks
pBlocks) [Seq Content]
children)
,(Identifier
"enum.item", \Maybe Text
_ Map Identifier Val
fields -> forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"body" Map Identifier Val
fields forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Blocks
pBlocks)
,(Identifier
"terms", \Maybe Text
_ Map Identifier Val
fields -> do
[Val]
children <- forall a. Vector a -> [a]
V.toList forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"children" Map Identifier Val
fields
[(Inlines, [Blocks])] -> Blocks
B.definitionList
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM
( \case
VTermItem Seq Content
t Seq Content
d -> do
Inlines
t' <- forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Inlines
pInlines Seq Content
t
Blocks
d' <- forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Blocks
pBlocks Seq Content
d
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Inlines
t', [Blocks
d'])
Val
_ -> forall (f :: * -> *) a. Applicative f => a -> f a
pure (forall a. Monoid a => a
mempty, [])
)
[Val]
children)
,(Identifier
"terms.item", \Maybe Text
_ Map Identifier Val
fields -> forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"body" Map Identifier Val
fields forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Blocks
pBlocks)
,(Identifier
"raw", \Maybe Text
mbident Map Identifier Val
fields -> do
Text
txt <- (Char -> Bool) -> Text -> Text
T.filter (forall a. Eq a => a -> a -> Bool
/= Char
'\r') forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"text" Map Identifier Val
fields
Maybe (Item [Text])
mblang <- forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"lang" Map Identifier Val
fields
let attr :: Attr
attr = (forall a. a -> Maybe a -> a
fromMaybe Text
"" Maybe Text
mbident, forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Item [Text]
l -> [Item [Text]
l]) Maybe (Item [Text])
mblang, [])
forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Attr -> Text -> Blocks
B.codeBlockWith Attr
attr Text
txt)
,(Identifier
"parbreak", \Maybe Text
_ Map Identifier Val
_ -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Monoid a => a
mempty)
,(Identifier
"block", \Maybe Text
mbident Map Identifier Val
fields ->
Attr -> Blocks -> Blocks
B.divWith (forall a. a -> Maybe a -> a
fromMaybe Text
"" Maybe Text
mbident, [], [])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"body" Map Identifier Val
fields forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Blocks
pBlocks))
,(Identifier
"place", \Maybe Text
_ Map Identifier Val
fields -> do
forall (m :: * -> *). PandocMonad m => Text -> P m ()
ignored Text
"parameters of place"
forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"body" Map Identifier Val
fields forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Blocks
pBlocks)
,(Identifier
"columns", \Maybe Text
_ Map Identifier Val
fields -> do
(Integer
cnt :: Integer) <- forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"count" Map Identifier Val
fields
Attr -> Blocks -> Blocks
B.divWith (Text
"", [Text
"columns-flow"], [(Text
"count", SourceName -> Text
T.pack (forall a. Show a => a -> SourceName
show Integer
cnt))])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"body" Map Identifier Val
fields forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Blocks
pBlocks))
,(Identifier
"rect", \Maybe Text
_ Map Identifier Val
fields ->
Attr -> Blocks -> Blocks
B.divWith (Text
"", [Text
"rect"], []) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"body" Map Identifier Val
fields forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Blocks
pBlocks))
,(Identifier
"circle", \Maybe Text
_ Map Identifier Val
fields ->
Attr -> Blocks -> Blocks
B.divWith (Text
"", [Text
"circle"], []) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"body" Map Identifier Val
fields forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Blocks
pBlocks))
,(Identifier
"ellipse", \Maybe Text
_ Map Identifier Val
fields ->
Attr -> Blocks -> Blocks
B.divWith (Text
"", [Text
"ellipse"], []) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"body" Map Identifier Val
fields forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Blocks
pBlocks))
,(Identifier
"polygon", \Maybe Text
_ Map Identifier Val
fields ->
Attr -> Blocks -> Blocks
B.divWith (Text
"", [Text
"polygon"], []) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"body" Map Identifier Val
fields forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Blocks
pBlocks))
,(Identifier
"square", \Maybe Text
_ Map Identifier Val
fields ->
Attr -> Blocks -> Blocks
B.divWith (Text
"", [Text
"square"], []) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"body" Map Identifier Val
fields forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Blocks
pBlocks))
,(Identifier
"align", \Maybe Text
_ Map Identifier Val
fields -> do
Val
alignment <- forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"alignment" Map Identifier Val
fields
Attr -> Blocks -> Blocks
B.divWith (Text
"", [], [(Text
"align", Val -> Text
repr Val
alignment)])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"body" Map Identifier Val
fields forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Blocks
pBlocks))
,(Identifier
"stack", \Maybe Text
_ Map Identifier Val
fields -> do
(Direction
dir :: Direction) <- forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"dir" Map Identifier Val
fields forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
`mplus` forall (f :: * -> *) a. Applicative f => a -> f a
pure Direction
Ltr
Vector Val
rawchildren <- forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"children" Map Identifier Val
fields
[Blocks]
children <-
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM
( \case
val :: Val
val@(VFraction {}) ->
forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Attr -> Blocks -> Blocks
B.divWith (Text
"", [], [(Text
"space", Val -> Text
repr Val
val)]) forall a. Monoid a => a
mempty
Val
val -> forall a (m :: * -> *).
(FromVal a, MonadPlus m, MonadFail m) =>
Val -> m a
fromVal Val
val forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Blocks
pBlocks
)
(forall a. Vector a -> [a]
V.toList Vector Val
rawchildren)
forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$
Attr -> Blocks -> Blocks
B.divWith (Text
"", [], [(Text
"stack", Val -> Text
repr (Direction -> Val
VDirection Direction
dir))]) forall a b. (a -> b) -> a -> b
$
forall a. Monoid a => [a] -> a
mconcat forall a b. (a -> b) -> a -> b
$
forall a b. (a -> b) -> [a] -> [b]
map (Attr -> Blocks -> Blocks
B.divWith (Text
"", [], [])) [Blocks]
children)
,(Identifier
"grid", \Maybe Text
mbident Map Identifier Val
fields -> do
[Blocks]
children <- forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"children" Map Identifier Val
fields forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Blocks
pBlocks) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Vector a -> [a]
V.toList
(Val
columns :: Val) <- forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"columns" Map Identifier Val
fields
let toWidth :: Val -> Maybe a
toWidth (VFraction Double
f) = forall a. a -> Maybe a
Just (forall a b. (RealFrac a, Integral b) => a -> b
floor forall a b. (a -> b) -> a -> b
$ Double
1000 forall a. Num a => a -> a -> a
* Double
f)
toWidth Val
_ = forall a. Maybe a
Nothing
let normalizeWidths :: [Maybe Int] -> [ColWidth]
normalizeWidths [Maybe Int]
xs =
let givenwidths :: [Int]
givenwidths = forall a. [Maybe a] -> [a]
catMaybes [Maybe Int]
xs
(Int
totgivenwidth :: Int) = forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum [Int]
givenwidths
avgwidth :: Int
avgwidth = Int
totgivenwidth forall a. Integral a => a -> a -> a
`div` forall (t :: * -> *) a. Foldable t => t a -> Int
length [Int]
givenwidths
totwidth :: Int
totwidth = Int
avgwidth forall a. Num a => a -> a -> a
* forall (t :: * -> *) a. Foldable t => t a -> Int
length [Maybe Int]
xs
in if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Int]
givenwidths
then forall a. Int -> a -> [a]
replicate (forall (t :: * -> *) a. Foldable t => t a -> Int
length [Maybe Int]
xs) ColWidth
B.ColWidthDefault
else
forall a b. (a -> b) -> [a] -> [b]
map
( \case
Just Int
x -> Double -> ColWidth
B.ColWidth (forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
x forall a. Fractional a => a -> a -> a
/ forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
totwidth)
Maybe Int
Nothing ->
Double -> ColWidth
B.ColWidth (forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
avgwidth forall a. Fractional a => a -> a -> a
/ forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
totwidth)
)
[Maybe Int]
xs
[ColWidth]
widths <- case Val
columns of
VInteger Integer
x -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall a. Int -> a -> [a]
replicate (forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
x) ColWidth
B.ColWidthDefault
VArray Vector Val
x -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ [Maybe Int] -> [ColWidth]
normalizeWidths forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map forall {a}. Integral a => Val -> Maybe a
toWidth (forall a. Vector a -> [a]
V.toList Vector Val
x)
Val
VNone -> forall (f :: * -> *) a. Applicative f => a -> f a
pure [ColWidth
B.ColWidthDefault]
Val
_ -> forall (m :: * -> *) a. MonadFail m => SourceName -> m a
fail forall a b. (a -> b) -> a -> b
$ SourceName
"Could not determine number of columns: " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> SourceName
show Val
columns
let numcols :: Int
numcols = forall (t :: * -> *) a. Foldable t => t a -> Int
length [ColWidth]
widths
Val
align <- forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"align" Map Identifier Val
fields
let toAlign :: Val -> Alignment
toAlign (VAlignment (Just Horiz
horiz) Maybe Vert
_) =
case Horiz
horiz of
Horiz
HorizStart -> Alignment
B.AlignLeft
Horiz
HorizLeft -> Alignment
B.AlignLeft
Horiz
HorizEnd -> Alignment
B.AlignRight
Horiz
HorizRight -> Alignment
B.AlignRight
Horiz
HorizCenter -> Alignment
B.AlignCenter
toAlign Val
_ = Alignment
B.AlignDefault
[Alignment]
aligns <-
case Val
align of
VAlignment {} -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall a. Int -> a -> [a]
replicate Int
numcols (Val -> Alignment
toAlign Val
align)
VArray Vector Val
v -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map Val -> Alignment
toAlign (forall a. Vector a -> [a]
V.toList Vector Val
v)
VFunction Maybe Identifier
_ Map Identifier Val
_ Function
f -> do
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM
( \Integer
colnum -> case Function -> [Val] -> Attempt Val
applyPureFunction
Function
f
[Integer -> Val
VInteger Integer
colnum, Integer -> Val
VInteger Integer
0] of
Success Val
x -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Val -> Alignment
toAlign Val
x
Failure SourceName
e -> forall (m :: * -> *) a. MonadFail m => SourceName -> m a
fail SourceName
e
)
[Integer
0 .. (forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
numcols forall a. Num a => a -> a -> a
- Integer
1)]
Val
_ -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall a. Int -> a -> [a]
replicate Int
numcols Alignment
B.AlignDefault
let colspecs :: [(Alignment, ColWidth)]
colspecs = forall a b. [a] -> [b] -> [(a, b)]
zip ([Alignment]
aligns forall a. [a] -> [a] -> [a]
++ forall a. a -> [a]
repeat Alignment
B.AlignDefault) [ColWidth]
widths
let rows :: [Row]
rows =
forall a b. (a -> b) -> [a] -> [b]
map (Attr -> [Cell] -> Row
B.Row Attr
B.nullAttr) forall a b. (a -> b) -> a -> b
$
forall a. Int -> [a] -> [[a]]
chunks Int
numcols forall a b. (a -> b) -> a -> b
$
forall a b. (a -> b) -> [a] -> [b]
map
( Attr -> Alignment -> RowSpan -> ColSpan -> [Block] -> Cell
B.Cell
Attr
B.nullAttr
Alignment
B.AlignDefault
(Int -> RowSpan
B.RowSpan Int
1)
(Int -> ColSpan
B.ColSpan Int
1)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Many a -> [a]
B.toList
)
[Blocks]
children
forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$
Attr
-> Caption
-> [(Alignment, ColWidth)]
-> TableHead
-> [TableBody]
-> TableFoot
-> Blocks
B.tableWith
(forall a. a -> Maybe a -> a
fromMaybe Text
"" Maybe Text
mbident, [], [])
(Maybe ShortCaption -> [Block] -> Caption
B.Caption forall a. Monoid a => a
mempty forall a. Monoid a => a
mempty)
[(Alignment, ColWidth)]
colspecs
(Attr -> [Row] -> TableHead
B.TableHead Attr
B.nullAttr [])
[Attr -> RowHeadColumns -> [Row] -> [Row] -> TableBody
B.TableBody Attr
B.nullAttr RowHeadColumns
0 [] [Row]
rows]
(Attr -> [Row] -> TableFoot
B.TableFoot Attr
B.nullAttr []))
,(Identifier
"table", \Maybe Text
mbident Map Identifier Val
fields ->
forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall (m :: * -> *) a. MonadPlus m => m a
mzero (\Maybe Text -> Map Identifier Val -> P m Blocks
f -> Maybe Text -> Map Identifier Val -> P m Blocks
f Maybe Text
mbident Map Identifier Val
fields) forall a b. (a -> b) -> a -> b
$ forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Identifier
"grid" forall (m :: * -> *).
PandocMonad m =>
Map Identifier (Maybe Text -> Map Identifier Val -> P m Blocks)
blockHandlers)
,(Identifier
"figure", \Maybe Text
mbident Map Identifier Val
fields -> do
Blocks
body <- forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"body" Map Identifier Val
fields forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Blocks
pBlocks
(Maybe (Seq Content)
mbCaption :: Maybe (Seq Content)) <- forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"caption" Map Identifier Val
fields
(Blocks
caption :: B.Blocks) <- forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. Monoid a => a
mempty (forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Blocks
pBlocks) Maybe (Seq Content)
mbCaption
forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ case forall a. Many a -> [a]
B.toList Blocks
body of
[B.Table Attr
attr Caption
_ [(Alignment, ColWidth)]
colspecs TableHead
thead [TableBody]
tbodies TableFoot
tfoot] ->
forall a. a -> Many a
B.singleton
(Attr
-> Caption
-> [(Alignment, ColWidth)]
-> TableHead
-> [TableBody]
-> TableFoot
-> Block
B.Table Attr
attr (Maybe ShortCaption -> [Block] -> Caption
B.Caption forall a. Maybe a
Nothing (forall a. Many a -> [a]
B.toList Blocks
caption)) [(Alignment, ColWidth)]
colspecs TableHead
thead [TableBody]
tbodies TableFoot
tfoot)
[Block]
_ -> Attr -> Caption -> Blocks -> Blocks
B.figureWith (forall a. a -> Maybe a -> a
fromMaybe Text
"" Maybe Text
mbident, [], [])
(Maybe ShortCaption -> [Block] -> Caption
B.Caption forall a. Maybe a
Nothing (forall a. Many a -> [a]
B.toList Blocks
caption)) Blocks
body)
,(Identifier
"line", \Maybe Text
_ Map Identifier Val
fields ->
case ( forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Identifier
"start" Map Identifier Val
fields
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Identifier
"end" Map Identifier Val
fields
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Identifier
"angle" Map Identifier Val
fields ) of
Maybe Val
Nothing -> forall (f :: * -> *) a. Applicative f => a -> f a
pure Blocks
B.horizontalRule
Maybe Val
_ -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Monoid a => a
mempty)
,(Identifier
"numbering", \Maybe Text
_ Map Identifier Val
fields -> do
Val
numStyle <- forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"numbering" Map Identifier Val
fields
(Vector Integer
nums :: V.Vector Integer) <- forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"numbers" Map Identifier Val
fields
let toText :: Val -> a
toText Val
v = forall a. a -> Maybe a -> a
fromMaybe a
"" forall a b. (a -> b) -> a -> b
$ forall a (m :: * -> *).
(FromVal a, MonadPlus m, MonadFail m) =>
Val -> m a
fromVal Val
v
let toNum :: Integer -> Text
toNum Integer
n =
case Val
numStyle of
VString Text
t -> Text -> Int -> Text
formatNumber Text
t (forall a b. (Integral a, Num b) => a -> b
fromIntegral Integer
n)
VFunction Maybe Identifier
_ Map Identifier Val
_ Function
f ->
case Function -> [Val] -> Attempt Val
applyPureFunction Function
f [Integer -> Val
VInteger Integer
n] of
Success Val
x -> forall {a}. (IsString a, FromVal a) => Val -> a
toText Val
x
Failure SourceName
_ -> Text
"?"
Val
_ -> Text
"?"
forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Inlines -> Blocks
B.plain forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Inlines
B.text forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Monoid a => [a] -> a
mconcat forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map Integer -> Text
toNum forall a b. (a -> b) -> a -> b
$ forall a. Vector a -> [a]
V.toList Vector Integer
nums)
,(Identifier
"footnote.entry", \Maybe Text
_ Map Identifier Val
fields ->
forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"body" Map Identifier Val
fields forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Blocks
pBlocks)
]
inlineHandlers :: PandocMonad m =>
M.Map Identifier (Maybe Text -> M.Map Identifier Val -> P m B.Inlines)
inlineHandlers :: forall (m :: * -> *).
PandocMonad m =>
Map Identifier (Maybe Text -> Map Identifier Val -> P m Inlines)
inlineHandlers = forall k a. Ord k => [(k, a)] -> Map k a
M.fromList
[(Identifier
"ref", \Maybe Text
_ Map Identifier Val
fields -> do
VLabel Text
target <- forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"target" Map Identifier Val
fields
Val
supplement' <- forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"supplement" Map Identifier Val
fields
Inlines
supplement <- case Val
supplement' of
Val
VAuto ->
forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Text -> Inlines
B.text (Text
"[" forall a. Semigroup a => a -> a -> a
<> Text
target forall a. Semigroup a => a -> a -> a
<> Text
"]")
VContent Seq Content
cs -> forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Inlines
pInlines Seq Content
cs
VFunction Maybe Identifier
_ Map Identifier Val
_ Function
_f ->
forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Text -> Inlines
B.text (Text
"[" forall a. Semigroup a => a -> a -> a
<> Text
target forall a. Semigroup a => a -> a -> a
<> Text
"]")
Val
_ -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Monoid a => a
mempty
forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Attr -> Text -> Text -> Inlines -> Inlines
B.linkWith (Text
"", [Text
"ref"], []) (Text
"#" forall a. Semigroup a => a -> a -> a
<> Text
target) Text
"" Inlines
supplement)
,(Identifier
"linebreak", \Maybe Text
_ Map Identifier Val
_ -> forall (f :: * -> *) a. Applicative f => a -> f a
pure Inlines
B.linebreak)
,(Identifier
"text", \Maybe Text
_ Map Identifier Val
fields -> do
Seq Content
body <- forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"body" Map Identifier Val
fields
(Maybe Text
mbweight :: Maybe Text) <- forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"weight" Map Identifier Val
fields
case Maybe Text
mbweight of
Just Text
"bold" -> Inlines -> Inlines
B.strong forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Inlines
pInlines Seq Content
body
Maybe Text
_ -> forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Inlines
pInlines Seq Content
body)
,(Identifier
"raw", \Maybe Text
_ Map Identifier Val
fields -> Text -> Inlines
B.code forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> Text -> Text
T.filter (forall a. Eq a => a -> a -> Bool
/= Char
'\r') forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"text" Map Identifier Val
fields)
,(Identifier
"footnote", \Maybe Text
_ Map Identifier Val
fields ->
Blocks -> Inlines
B.note forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"body" Map Identifier Val
fields forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Blocks
pBlocks))
,(Identifier
"cite", \Maybe Text
_ Map Identifier Val
fields -> do
[Text]
keys <- forall a. Vector a -> [a]
V.toList forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"keys" Map Identifier Val
fields
let toCitation :: Text -> Citation
toCitation Text
key =
B.Citation
{ citationId :: Text
B.citationId = Text
key,
citationPrefix :: ShortCaption
B.citationPrefix = forall a. Monoid a => a
mempty,
citationSuffix :: ShortCaption
B.citationSuffix = forall a. Monoid a => a
mempty,
citationMode :: CitationMode
B.citationMode = CitationMode
B.NormalCitation,
citationNoteNum :: Int
B.citationNoteNum = Int
0,
citationHash :: Int
B.citationHash = Int
0
}
let citations :: [Citation]
citations = forall a b. (a -> b) -> [a] -> [b]
map Text -> Citation
toCitation [Text]
keys
forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ [Citation] -> Inlines -> Inlines
B.cite [Citation]
citations (Text -> Inlines
B.text forall a b. (a -> b) -> a -> b
$ Text
"[" forall a. Semigroup a => a -> a -> a
<> Text -> [Text] -> Text
T.intercalate Text
"," [Text]
keys forall a. Semigroup a => a -> a -> a
<> Text
"]"))
,(Identifier
"lower", \Maybe Text
_ Map Identifier Val
fields -> do
Seq Content
body <- forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"text" Map Identifier Val
fields
forall a b. Walkable a b => (a -> a) -> b -> b
walk ((Text -> Text) -> Inline -> Inline
modString Text -> Text
T.toLower) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Inlines
pInlines Seq Content
body)
,(Identifier
"upper", \Maybe Text
_ Map Identifier Val
fields -> do
Seq Content
body <- forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"text" Map Identifier Val
fields
forall a b. Walkable a b => (a -> a) -> b -> b
walk ((Text -> Text) -> Inline -> Inline
modString Text -> Text
T.toUpper) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Inlines
pInlines Seq Content
body)
,(Identifier
"emph", \Maybe Text
_ Map Identifier Val
fields -> do
Seq Content
body <- forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"body" Map Identifier Val
fields
Inlines -> Inlines
B.emph forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Inlines
pInlines Seq Content
body)
,(Identifier
"strong", \Maybe Text
_ Map Identifier Val
fields -> do
Seq Content
body <- forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"body" Map Identifier Val
fields
Inlines -> Inlines
B.strong forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Inlines
pInlines Seq Content
body)
,(Identifier
"sub", \Maybe Text
_ Map Identifier Val
fields -> do
Seq Content
body <- forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"body" Map Identifier Val
fields
Inlines -> Inlines
B.subscript forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Inlines
pInlines Seq Content
body)
,(Identifier
"super", \Maybe Text
_ Map Identifier Val
fields -> do
Seq Content
body <- forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"body" Map Identifier Val
fields
Inlines -> Inlines
B.superscript forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Inlines
pInlines Seq Content
body)
,(Identifier
"strike", \Maybe Text
_ Map Identifier Val
fields -> do
Seq Content
body <- forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"body" Map Identifier Val
fields
Inlines -> Inlines
B.strikeout forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Inlines
pInlines Seq Content
body)
,(Identifier
"smallcaps", \Maybe Text
_ Map Identifier Val
fields -> do
Seq Content
body <- forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"body" Map Identifier Val
fields
Inlines -> Inlines
B.smallcaps forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Inlines
pInlines Seq Content
body)
,(Identifier
"underline", \Maybe Text
_ Map Identifier Val
fields -> do
Seq Content
body <- forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"body" Map Identifier Val
fields
Inlines -> Inlines
B.underline forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Inlines
pInlines Seq Content
body)
,(Identifier
"link", \Maybe Text
_ Map Identifier Val
fields -> do
Val
dest <- forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"dest" Map Identifier Val
fields
Text
src <- case Val
dest of
VString Text
t -> forall (f :: * -> *) a. Applicative f => a -> f a
pure Text
t
VLabel Text
t -> forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Text
"#" forall a. Semigroup a => a -> a -> a
<> Text
t
VDict OMap Identifier Val
_ -> do
forall (m :: * -> *). PandocMonad m => Text -> P m ()
ignored Text
"link to location, linking to #"
forall (f :: * -> *) a. Applicative f => a -> f a
pure Text
"#"
Val
_ -> forall (m :: * -> *) a. MonadFail m => SourceName -> m a
fail forall a b. (a -> b) -> a -> b
$ SourceName
"Expected string or label for dest"
Seq Content
body <- forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"body" Map Identifier Val
fields
Inlines
description <-
if forall (t :: * -> *) a. Foldable t => t a -> Bool
null Seq Content
body
then
forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$
Text -> Inlines
B.text forall a b. (a -> b) -> a -> b
$
if Text
"mailto:" Text -> Text -> Bool
`T.isPrefixOf` Text
src
then Int -> Text -> Text
T.drop Int
7 Text
src
else
if Text
"tel:" Text -> Text -> Bool
`T.isPrefixOf` Text
src
then Int -> Text -> Text
T.drop Int
4 Text
src
else Text
src
else forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Inlines
pInlines Seq Content
body forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents
(forall a. [a] -> Many a
B.fromList forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Block] -> ShortCaption
blocksToInlines forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Many a -> [a]
B.toList forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => P m Blocks
pBlocks) Seq Content
body
forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Text -> Text -> Inlines -> Inlines
B.link Text
src Text
"" Inlines
description)
,(Identifier
"image", \Maybe Text
_ Map Identifier Val
fields -> do
Text
path <- forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"path" Map Identifier Val
fields
Inlines
alt <- (Text -> Inlines
B.text forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"alt" Map Identifier Val
fields) forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
`mplus` forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Monoid a => a
mempty
(Maybe Text
mbwidth :: Maybe Text) <-
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Bool -> Length -> Text
renderLength Bool
False) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"width" Map Identifier Val
fields
(Maybe Text
mbheight :: Maybe Text) <-
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Bool -> Length -> Text
renderLength Bool
False) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"height" Map Identifier Val
fields
let attr :: Attr
attr =
( Text
"",
[],
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Text
x -> [(Text
"width", Text
x)]) Maybe Text
mbwidth
forall a. [a] -> [a] -> [a]
++ forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\Text
x -> [(Text
"height", Text
x)]) Maybe Text
mbheight
)
forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Attr -> Text -> Text -> Inlines -> Inlines
B.imageWith Attr
attr Text
path Text
"" Inlines
alt)
,(Identifier
"box", \Maybe Text
_ Map Identifier Val
fields -> do
Seq Content
body <- forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"body" Map Identifier Val
fields
Attr -> Inlines -> Inlines
B.spanWith (Text
"", [Text
"box"], []) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Inlines
pInlines Seq Content
body)
,(Identifier
"h", \Maybe Text
_ Map Identifier Val
fields -> do
Length
amount <- forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"amount" Map Identifier Val
fields forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
`mplus` forall (f :: * -> *) a. Applicative f => a -> f a
pure (Double -> LUnit -> Length
LExact Double
1 LUnit
LEm)
let em :: Rational
em = case Length
amount of
LExact Double
x LUnit
LEm -> forall a. Real a => a -> Rational
toRational Double
x
Length
_ -> case Length
amount forall a. Semigroup a => a -> a -> a
<> Double -> LUnit -> Length
LExact Double
0 LUnit
LPt of
LExact Double
x LUnit
LPt -> forall a. Real a => a -> Rational
toRational Double
x forall a. Fractional a => a -> a -> a
/ Rational
12
Length
_ -> Rational
1 forall a. Fractional a => a -> a -> a
/ Rational
3
forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Text -> Inlines
B.text forall a b. (a -> b) -> a -> b
$ Rational -> Text
getSpaceChars Rational
em)
,(Identifier
"place", \Maybe Text
_ Map Identifier Val
fields -> do
forall (m :: * -> *). PandocMonad m => Text -> P m ()
ignored Text
"parameters of place"
forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"body" Map Identifier Val
fields forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Inlines
pInlines)
,(Identifier
"align", \Maybe Text
_ Map Identifier Val
fields -> do
Val
alignment <- forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"alignment" Map Identifier Val
fields
Attr -> Inlines -> Inlines
B.spanWith (Text
"", [], [(Text
"align", Val -> Text
repr Val
alignment)])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"body" Map Identifier Val
fields forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents forall (m :: * -> *). PandocMonad m => P m Inlines
pInlines))
,(Identifier
"math.equation", \Maybe Text
_ Map Identifier Val
fields -> do
Seq Content
body <- forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"body" Map Identifier Val
fields
Bool
display <- forall (m :: * -> *) a.
(MonadFail m, MonadPlus m, FromVal a) =>
Identifier -> Map Identifier Val -> m a
getField Identifier
"block" Map Identifier Val
fields
(if Bool
display then Text -> Inlines
B.displayMath else Text -> Inlines
B.math) forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Exp] -> Text
writeTeX forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). PandocMonad m => Seq Content -> P m [Exp]
pMathMany Seq Content
body)
]
pPara :: PandocMonad m => P m B.Blocks
pPara :: forall (m :: * -> *). PandocMonad m => P m Blocks
pPara =
Inlines -> Blocks
B.para forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> Inlines
B.trimInlines forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 forall (m :: * -> *). PandocMonad m => P m Inlines
pInline forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional forall (m :: * -> *). PandocMonad m => P m ()
pParBreak)
pParBreak :: PandocMonad m => P m ()
pParBreak :: forall (m :: * -> *). PandocMonad m => P m ()
pParBreak =
forall (f :: * -> *) a. Functor f => f a -> f ()
void forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *).
PandocMonad m =>
(Content -> Bool) -> P m Content
pTok
( \case
Elt Identifier
"parbreak" Maybe SourcePos
_ Map Identifier Val
_ -> Bool
True
Content
_ -> Bool
False
)
pWithContents :: PandocMonad m => P m a -> Seq Content -> P m a
pWithContents :: forall (m :: * -> *) a.
PandocMonad m =>
P m a -> Seq Content -> P m a
pWithContents P m a
pa Seq Content
cs = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
[Content]
inp <- forall (m :: * -> *) s u. Monad m => ParsecT s u m s
getInput
forall (m :: * -> *) s u. Monad m => s -> ParsecT s u m ()
setInput forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a. Foldable t => t a -> [a]
F.toList Seq Content
cs
a
res <- P m a
pa
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
forall (m :: * -> *) s u. Monad m => s -> ParsecT s u m ()
setInput [Content]
inp
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
res
pInlines :: PandocMonad m => P m B.Inlines
pInlines :: forall (m :: * -> *). PandocMonad m => P m Inlines
pInlines = forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many forall (m :: * -> *). PandocMonad m => P m Inlines
pInline
modString :: (Text -> Text) -> B.Inline -> B.Inline
modString :: (Text -> Text) -> Inline -> Inline
modString Text -> Text
f (B.Str Text
t) = Text -> Inline
B.Str (Text -> Text
f Text
t)
modString Text -> Text
_ Inline
x = Inline
x