{-# 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.Docs
, module Knit.Effect.PandocMonad
, module Knit.Effect.Logger
)
where
import Polysemy ( Member
, Sem
, Lift
)
import Knit.Effect.Pandoc ( ToPandoc
, Requirement(..)
, PandocReadFormat(..)
, PandocWriteFormat(..)
, Pandocs
, newPandoc
)
import Knit.Effect.Docs ( NamedDoc(..) )
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 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
:: MonadIO m
=> Maybe T.Text
-> [KLog.LogSeverity]
-> PandocWriterConfig
-> P.Sem (KnitEffectDocsStack m) ()
-> m (Either PA.PandocError [KP.NamedDoc TL.Text])
knitHtmls loggingPrefixM ls writeConfig =
consumeKnitEffectStack loggingPrefixM ls . KD.toNamedDocListWithM
(fmap BH.renderHtml . KO.toBlazeDocument writeConfig)
knitHtml
:: MonadIO m
=> Maybe T.Text
-> [KLog.LogSeverity]
-> PandocWriterConfig
-> P.Sem (KnitEffectDocStack m) ()
-> m (Either PA.PandocError TL.Text)
knitHtml loggingPrefixM ls writeConfig =
fmap (fmap (fmap BH.renderHtml)) (consumeKnitEffectStack loggingPrefixM ls)
. KO.pandocWriterToBlazeDocument writeConfig
type KnitBase m effs = (MonadIO m, P.Member (P.Lift m) effs)
liftKnit :: Member (Lift m) r => m a -> Sem 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)
consumeKnitEffectStack
:: forall m a
. MonadIO m
=> Maybe T.Text
-> [KLog.LogSeverity]
-> P.Sem (KnitEffectStack m) a
-> m (Either PA.PandocError a)
consumeKnitEffectStack loggingPrefixM ls =
P.runM
. PI.runIO @m
. PE.runError
. KLog.filteredLogEntriesToIO ls
. KPM.interpretInIO
. maybe id KLog.wrapPrefix loggingPrefixM