{-# LANGUAGE ExtendedDefaultRules #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE UndecidableInstances #-}
module Knit.Report
(
knitHtml
, knitHtmls
, liftKnit
, KnitBase
, module Knit.Report.Input.Table.Colonnade
, module Knit.Report.Input.MarkDown.PandocMarkDown
, module Knit.Report.Input.Html
, module Knit.Report.Input.Html.Blaze
, module Knit.Report.Input.Html.Lucid
, module Knit.Report.Input.Latex
, module Knit.Report.Input.Visualization.Hvega
, module Knit.Report.Output
, module Knit.Report.Output.Html
, module Polysemy
, module Knit.Effect.Pandoc
, module Knit.Effect.PandocMonad
, module Knit.Effect.Logger
)
where
import Polysemy ( Member
, Semantic
, Lift
)
import Knit.Effect.Pandoc ( ToPandoc
, Requirement(..)
, PandocReadFormat(..)
, PandocWriteFormat(..)
, Pandocs
)
import Knit.Effect.PandocMonad
import Knit.Effect.Logger ( LogSeverity(..)
, logAll
, nonDiagnostic
, logLE
, wrapPrefix
, filteredLogEntriesToIO
, LogWithPrefixesLE
)
import Knit.Report.Input.Table.Colonnade
( addColonnadeTextTable
, addColonnadeHtmlTable
, addColonnadeCellTable
)
import Knit.Report.Input.MarkDown.PandocMarkDown
( addMarkDown )
import Knit.Report.Input.Html ( addStrictTextHtml
, addLazyTextHtml
)
import Knit.Report.Input.Html.Blaze ( addBlaze )
import Knit.Report.Input.Html.Lucid ( addLucid )
import Knit.Report.Input.Latex ( addLatex )
import Knit.Report.Input.Visualization.Hvega
( addHvega )
import Knit.Report.Output ( PandocWriterConfig(..) )
import Knit.Report.Output.Html ( pandocWriterToBlazeDocument
, mindocOptionsF
)
import Text.Pandoc ( PandocError )
import Control.Monad.Except ( MonadIO )
import qualified Data.Text as T
import qualified Data.Text.Lazy as TL
import GHC.Exts ( Constraint )
import qualified Polysemy as P
import qualified Polysemy.Error as PE
import qualified Polysemy.IO as PI
import qualified Text.Pandoc as PA
import qualified Text.Blaze.Html.Renderer.Text as BH
import qualified Knit.Report.Output.Html as KO
import qualified Knit.Effect.Docs as KD
import qualified Knit.Effect.Pandoc as KP
import qualified Knit.Effect.PandocMonad as KPM
import qualified Knit.Effect.Logger as KLog
knitHtmls
:: forall m
. (MonadIO m, LastMember (P.Lift m) (KnitEffectStack m))
=> Maybe T.Text
-> [KLog.LogSeverity]
-> PandocWriterConfig
-> P.Semantic (KnitEffectDocsStack m) ()
-> m (Either PA.PandocError [KP.NamedDoc TL.Text])
knitHtmls loggingPrefixM ls writeConfig =
runSemT (consumeKnitEffectMany loggingPrefixM ls writeConfig)
knitHtml
:: forall m
. (MonadIO m, LastMember (P.Lift m) (KnitEffectStack m))
=> Maybe T.Text
-> [KLog.LogSeverity]
-> PandocWriterConfig
-> P.Semantic (KnitEffectDocStack m) ()
-> m (Either PA.PandocError TL.Text)
knitHtml loggingPrefixM ls writeConfig =
runSemT (consumeKnitEffectOne loggingPrefixM ls writeConfig)
type KnitBase m effs = (MonadIO m, P.Member (P.Lift m) effs)
liftKnit :: Member (Lift m) r => m a -> Semantic r a
liftKnit = P.sendM
type KnitEffectStack m =
'[ KPM.Pandoc
, KLog.Logger KLog.LogEntry
, KLog.PrefixLog
, PE.Error PA.PandocError
, P.Lift IO
, P.Lift m
]
type KnitEffectDocsStack m = (KD.Docs KP.PandocWithRequirements ': KnitEffectStack m)
type KnitEffectDocStack m = (KP.ToPandoc ': KnitEffectStack m)
type family LastMember (eff :: k) (r :: [k]) :: Constraint where
LastMember eff '[] = ()
LastMember eff (e : es) = (P.Member eff (e ': es), LastMember eff es)
runSemT
:: Monad m
=> (P.Semantic r a -> P.Semantic '[P.Lift m] b)
-> P.Semantic r a
-> m b
runSemT consume = P.runM . consume
consumeKnitEffectStack
:: forall m a
. (MonadIO m, LastMember (P.Lift m) (KnitEffectStack m))
=> Maybe T.Text
-> [KLog.LogSeverity]
-> P.Semantic (KnitEffectStack m) a
-> P.Semantic '[P.Lift m] (Either PA.PandocError a)
consumeKnitEffectStack loggingPrefixM ls =
PI.runIO @m
. PE.runError
. KLog.filteredLogEntriesToIO ls
. KPM.interpretInIO
. maybe id KLog.wrapPrefix loggingPrefixM
consumeKnitEffectMany
:: forall m
. (MonadIO m, LastMember (P.Lift m) (KnitEffectStack m))
=> Maybe T.Text
-> [KLog.LogSeverity]
-> PandocWriterConfig
-> P.Semantic (KnitEffectDocsStack m) ()
-> P.Semantic
'[P.Lift m]
(Either PA.PandocError [KP.NamedDoc TL.Text])
consumeKnitEffectMany loggingPrefixM ls writeConfig =
consumeKnitEffectStack @m loggingPrefixM ls . KD.toNamedDocListWithM
(fmap BH.renderHtml . KO.toBlazeDocument writeConfig)
consumeKnitEffectOne
:: forall m
. (MonadIO m, LastMember (P.Lift m) (KnitEffectStack m))
=> Maybe T.Text
-> [KLog.LogSeverity]
-> PandocWriterConfig
-> P.Semantic (KnitEffectDocStack m) ()
-> P.Semantic '[P.Lift m] (Either PA.PandocError TL.Text)
consumeKnitEffectOne loggingPrefixM ls writeConfig =
fmap (fmap (fmap BH.renderHtml)) (consumeKnitEffectStack @m loggingPrefixM ls)
. KO.pandocWriterToBlazeDocument writeConfig