{-# LANGUAGE Rank2Types, OverloadedStrings, FlexibleContexts #-}
module Text.Pandoc.CrossRef.References.Blocks.Table where
import Control.Monad.Reader.Class
import Text.Pandoc.Definition
import Text.Pandoc.Shared (blocksToInlines)
import Data.Function ((&))
import Text.Pandoc.CrossRef.References.Monad
import Text.Pandoc.CrossRef.References.Blocks.Util
import Text.Pandoc.CrossRef.Util.Options
import Text.Pandoc.CrossRef.Util.Template
import Text.Pandoc.CrossRef.Util.Util
runTable :: Attr -> Maybe Attr -> Maybe ShortCaption -> Block -> [Block] -> [ColSpec] -> TableHead -> [TableBody] -> TableFoot -> WS (ReplacedResult Block)
runTable :: Attr
-> Maybe Attr
-> Maybe ShortCaption
-> Block
-> [Block]
-> [ColSpec]
-> TableHead
-> [TableBody]
-> TableFoot
-> WS (ReplacedResult Block)
runTable (Text
label, [Text]
clss, [(Text, Text)]
attrs) Maybe Attr
mtattr Maybe ShortCaption
short Block
btitle [Block]
rest [ColSpec]
colspec TableHead
header [TableBody]
cells TableFoot
foot = do
Options
opts <- forall r (m :: * -> *). MonadReader r m => m r
ask
ShortCaption
idxStr <- Either Text Text
-> [(Text, Text)] -> ShortCaption -> SPrefix -> WS ShortCaption
replaceAttr (forall a b. b -> Either a b
Right Text
label) [(Text, Text)]
attrs ShortCaption
title SPrefix
SPfxTbl
let title' :: ShortCaption
title' =
case Options -> Maybe Format
outFormat Options
opts of
Maybe Format
f | Maybe Format -> Bool
isLatexFormat Maybe Format
f ->
Format -> Text -> Inline
RawInline (Text -> Format
Format Text
"latex") (Text -> Text
mkLaTeXLabel Text
label) forall a. a -> [a] -> [a]
: ShortCaption
title
Maybe Format
_ -> forall a b.
MkTemplate a b =>
ShortCaption -> ShortCaption -> b -> [a]
applyTemplate ShortCaption
idxStr ShortCaption
title forall a b. (a -> b) -> a -> b
$ Options -> Template
tableTemplate Options
opts
caption' :: Caption
caption' = Maybe ShortCaption -> [Block] -> Caption
Caption Maybe ShortCaption
short (ShortCaption -> ShortCaption -> Block -> Block
walkReplaceInlines ShortCaption
title' ShortCaption
title Block
btitleforall a. a -> [a] -> [a]
:[Block]
rest)
forall (m :: * -> *) a. Monad m => a -> m (ReplacedResult a)
replaceNoRecurse forall a b. (a -> b) -> a -> b
$ (Maybe Attr
mtattr forall a b. a -> (a -> b) -> b
&
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
(Attr
-> Caption
-> [ColSpec]
-> TableHead
-> [TableBody]
-> TableFoot
-> Block
Table (Text
label, [Text]
clss, Options -> ShortCaption -> [(Text, Text)] -> [(Text, Text)]
setLabel Options
opts ShortCaption
idxStr [(Text, Text)]
attrs))
(\Attr
tattr Caption
a [ColSpec]
b TableHead
c [TableBody]
d -> Attr -> [Block] -> Block
Div (Text
label, [Text]
clss, Options -> ShortCaption -> [(Text, Text)] -> [(Text, Text)]
setLabel Options
opts ShortCaption
idxStr [(Text, Text)]
attrs) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. Attr
-> Caption
-> [ColSpec]
-> TableHead
-> [TableBody]
-> TableFoot
-> Block
Table Attr
tattr Caption
a [ColSpec]
b TableHead
c [TableBody]
d)
)
Caption
caption' [ColSpec]
colspec TableHead
header [TableBody]
cells TableFoot
foot
where title :: ShortCaption
title = [Block] -> ShortCaption
blocksToInlines [Block
btitle]