{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE NoImplicitPrelude #-}
module Text.Pandoc.Filter.Plot.Renderers.D2
( d2,
d2SupportedSaveFormats,
)
where
import Text.Pandoc.Filter.Plot.Renderers.Prelude
d2 :: PlotM Renderer
d2 :: PlotM Renderer
d2 = do
Text
cmdargs <- (Configuration -> Text) -> PlotM Text
forall a. (Configuration -> a) -> PlotM a
asksConfig Configuration -> Text
d2CmdArgs
Renderer -> PlotM Renderer
forall a. a -> StateT PlotState (ReaderT RuntimeEnv IO) a
forall (m :: * -> *) a. Monad m => a -> m a
return
(Renderer -> PlotM Renderer) -> Renderer -> PlotM Renderer
forall a b. (a -> b) -> a -> b
$ Renderer
{ rendererToolkit :: Toolkit
rendererToolkit = Toolkit
D2,
rendererCapture :: FigureSpec -> FilePath -> Text
rendererCapture = FigureSpec -> FilePath -> Text
d2Capture,
rendererCommand :: OutputSpec -> Text
rendererCommand = Text -> OutputSpec -> Text
d2Command Text
cmdargs,
rendererAvailability :: AvailabilityCheck
rendererAvailability = (Executable -> Text) -> AvailabilityCheck
CommandSuccess ((Executable -> Text) -> AvailabilityCheck)
-> (Executable -> Text) -> AvailabilityCheck
forall a b. (a -> b) -> a -> b
$ \Executable
exe -> [st|#{pathToExe exe} -v|],
rendererSupportedSaveFormats :: [SaveFormat]
rendererSupportedSaveFormats = [SaveFormat]
d2SupportedSaveFormats,
rendererChecks :: [Text -> CheckResult]
rendererChecks = [Text -> CheckResult]
forall a. Monoid a => a
mempty,
rendererLanguage :: Text
rendererLanguage = Text
"d2",
rendererComment :: Text -> Text
rendererComment = Text -> Text -> Text
forall a. Monoid a => a -> a -> a
mappend Text
"# ",
rendererScriptExtension :: FilePath
rendererScriptExtension = FilePath
".d2"
}
d2SupportedSaveFormats :: [SaveFormat]
d2SupportedSaveFormats :: [SaveFormat]
d2SupportedSaveFormats = [SaveFormat
PNG, SaveFormat
PDF, SaveFormat
SVG]
d2Command :: Text -> OutputSpec -> Text
d2Command :: Text -> OutputSpec -> Text
d2Command Text
cmdargs OutputSpec {FilePath
FigureSpec
Executable
oFigureSpec :: FigureSpec
oScriptPath :: FilePath
oFigurePath :: FilePath
oExecutable :: Executable
oCWD :: FilePath
oFigureSpec :: OutputSpec -> FigureSpec
oScriptPath :: OutputSpec -> FilePath
oFigurePath :: OutputSpec -> FilePath
oExecutable :: OutputSpec -> Executable
oCWD :: OutputSpec -> FilePath
..} = [st|#{pathToExe oExecutable} #{cmdargs} "#{oScriptPath}" "#{oFigurePath}"|]
d2Capture :: FigureSpec -> FilePath -> Script
d2Capture :: FigureSpec -> FilePath -> Text
d2Capture FigureSpec {Bool
Int
FilePath
[FilePath]
[(Text, Text)]
Attr
Text
Renderer
SaveFormat
Executable
renderer_ :: Renderer
fsExecutable :: Executable
caption :: Text
withSource :: Bool
script :: Text
saveFormat :: SaveFormat
directory :: FilePath
dpi :: Int
dependencies :: [FilePath]
extraAttrs :: [(Text, Text)]
blockAttrs :: Attr
renderer_ :: FigureSpec -> Renderer
fsExecutable :: FigureSpec -> Executable
caption :: FigureSpec -> Text
withSource :: FigureSpec -> Bool
script :: FigureSpec -> Text
saveFormat :: FigureSpec -> SaveFormat
directory :: FigureSpec -> FilePath
dpi :: FigureSpec -> Int
dependencies :: FigureSpec -> [FilePath]
extraAttrs :: FigureSpec -> [(Text, Text)]
blockAttrs :: FigureSpec -> Attr
..} FilePath
_ = Text
script