Copyright | (c) Laurent P René de Cotret 2019 - present |
---|---|
License | GNU GPL, version 2 or above |
Maintainer | [email protected] |
Stability | internal |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
Text.Pandoc.Filter.Plot.Internal
Description
This module re-exports internal pandoc-plot functionality. The external use of content from this module is discouraged.
Synopsis
- executable :: Toolkit -> PlotM Executable
- availableToolkits :: Configuration -> IO [Toolkit]
- unavailableToolkits :: Configuration -> IO [Toolkit]
- supportedSaveFormats :: Toolkit -> [SaveFormat]
- renderer :: Toolkit -> PlotM Renderer
- preambleSelector :: Toolkit -> Configuration -> Script
- parseExtraAttrs :: Toolkit -> Map Text Text -> Map Text Text
- availableToolkitsM :: PlotM [Toolkit]
- unavailableToolkitsM :: PlotM [Toolkit]
- data OutputSpec = OutputSpec {}
- data Executable
- data Renderer = Renderer {
- rendererToolkit :: Toolkit
- rendererCapture :: FigureSpec -> FilePath -> Script
- rendererCommand :: OutputSpec -> Text
- rendererAvailability :: AvailabilityCheck
- rendererSupportedSaveFormats :: [SaveFormat]
- rendererChecks :: [Script -> CheckResult]
- rendererLanguage :: Text
- rendererComment :: Text -> Text
- rendererScriptExtension :: String
- data ScriptResult
- runScriptIfNecessary :: FigureSpec -> PlotM ScriptResult
- runTempScript :: FigureSpec -> PlotM ScriptResult
- figurePath :: FigureSpec -> PlotM FilePath
- sourceCodePath :: FigureSpec -> PlotM FilePath
- data ParseFigureResult
- parseFigureSpec :: Block -> PlotM ParseFigureResult
- plotToolkit :: Block -> Maybe Toolkit
- captionReader :: Format -> Text -> Maybe [Inline]
- configuration :: FilePath -> IO Configuration
- defaultConfiguration :: Configuration
- configurationPathMeta :: Pandoc -> Maybe FilePath
- cleanOutputDirs :: Walkable Block b => Configuration -> b -> IO [FilePath]
- outputDirs :: Walkable Block b => b -> PlotM [FilePath]
- readDoc :: FilePath -> IO Pandoc
- data FigureSpec = FigureSpec {
- renderer_ :: !Renderer
- fsExecutable :: Executable
- caption :: !Text
- withSource :: !Bool
- script :: !Script
- saveFormat :: !SaveFormat
- directory :: !FilePath
- dpi :: !Int
- dependencies :: ![FilePath]
- extraAttrs :: ![(Text, Text)]
- blockAttrs :: !Attr
- data Verbosity
- liftIO :: MonadIO m => IO a -> m a
- ask :: MonadReader r m => m r
- asks :: MonadReader r m => (r -> a) -> m a
- runCommand :: FilePath -> Text -> PlotM (ExitCode, Text)
- cls :: Toolkit -> Text
- executable :: Toolkit -> PlotM Executable
- isWindows :: Bool
- data SaveFormat
- data Configuration = Configuration {
- defaultDirectory :: !FilePath
- defaultWithSource :: !Bool
- defaultDPI :: !Int
- defaultSaveFormat :: !SaveFormat
- defaultDependencies :: ![FilePath]
- captionFormat :: !Format
- sourceCodeLabel :: !Text
- strictMode :: !Bool
- logVerbosity :: !Verbosity
- logSink :: !LogSink
- matplotlibPreamble :: !Script
- plotlyPythonPreamble :: !Script
- plotlyRPreamble :: !Script
- matlabPreamble :: !Script
- mathematicaPreamble :: !Script
- octavePreamble :: !Script
- ggplot2Preamble :: !Script
- gnuplotPreamble :: !Script
- graphvizPreamble :: !Script
- bokehPreamble :: !Script
- plotsjlPreamble :: !Script
- plantumlPreamble :: !Script
- sagemathPreamble :: !Script
- d2Preamble :: !Script
- asyPreamble :: !Script
- mermaidPreamble :: !Script
- matplotlibExe :: !FilePath
- matlabExe :: !FilePath
- plotlyPythonExe :: !FilePath
- plotlyRExe :: !FilePath
- mathematicaExe :: !FilePath
- octaveExe :: !FilePath
- ggplot2Exe :: !FilePath
- gnuplotExe :: !FilePath
- graphvizExe :: !FilePath
- bokehExe :: !FilePath
- plotsjlExe :: !FilePath
- plantumlExe :: !FilePath
- sagemathExe :: !FilePath
- d2Exe :: !FilePath
- asyExe :: !FilePath
- mermaidExe :: !FilePath
- matplotlibCmdArgs :: !Text
- matlabCmdArgs :: !Text
- plotlyPythonCmdArgs :: !Text
- plotlyRCmdArgs :: !Text
- mathematicaCmdArgs :: !Text
- octaveCmdArgs :: !Text
- ggplot2CmdArgs :: !Text
- gnuplotCmdArgs :: !Text
- graphvizCmdArgs :: !Text
- bokehCmdArgs :: !Text
- plotsjlCmdArgs :: !Text
- plantumlCmdArgs :: !Text
- sagemathCmdArgs :: !Text
- d2CmdArgs :: !Text
- asyCmdArgs :: !Text
- mermaidCmdArgs :: !Text
- matplotlibTightBBox :: !Bool
- matplotlibTransparent :: !Bool
- data LogSink
- type Script = Text
- data Toolkit
- toolkits :: [Toolkit]
- type PlotM = StateT PlotState (ReaderT RuntimeEnv IO)
- data RuntimeEnv = RuntimeEnv {}
- asksConfig :: (Configuration -> a) -> PlotM a
- debug :: (MonadLogger m, MonadIO m) => Text -> m ()
- mapConcurrentlyN :: Traversable t => Int -> (a -> PlotM b) -> t a -> PlotM (t b)
- runPlotM :: Maybe Format -> Configuration -> PlotM a -> IO a
- throwStrictError :: Text -> PlotM ()
- data OutputSpec = OutputSpec {}
- data Executable
- data Renderer = Renderer {
- rendererToolkit :: Toolkit
- rendererCapture :: FigureSpec -> FilePath -> Script
- rendererCommand :: OutputSpec -> Text
- rendererAvailability :: AvailabilityCheck
- rendererSupportedSaveFormats :: [SaveFormat]
- rendererChecks :: [Script -> CheckResult]
- rendererLanguage :: Text
- rendererComment :: Text -> Text
- rendererScriptExtension :: String
- newtype PlotState = PlotState (MVar (Map FilePath FileHash))
- withPrependedPath :: FilePath -> PlotM a -> PlotM a
- fileHash :: FilePath -> PlotM FileHash
- err :: (MonadLogger m, MonadIO m) => Text -> m ()
- warning :: (MonadLogger m, MonadIO m) => Text -> m ()
- info :: (MonadLogger m, MonadIO m) => Text -> m ()
- data AvailabilityCheck
- = CommandSuccess (Executable -> Text)
- | ExecutableExists
- data CheckResult
- data InclusionKey
- extension :: SaveFormat -> String
- inclusionKeys :: [InclusionKey]
- exeFromPath :: FilePath -> Executable
- pathToExe :: Executable -> FilePath
- toFigure :: Format -> FigureSpec -> PlotM Block
- extractPlot :: Text -> Text
Documentation
executable :: Toolkit -> PlotM Executable Source #
Find an executable.
availableToolkits :: Configuration -> IO [Toolkit] Source #
List of toolkits available on this machine. The executables to look for are taken from the configuration.
unavailableToolkits :: Configuration -> IO [Toolkit] Source #
List of toolkits not available on this machine. The executables to look for are taken from the configur
supportedSaveFormats :: Toolkit -> [SaveFormat] Source #
Save formats supported by this renderer.
renderer :: Toolkit -> PlotM Renderer Source #
Get the renderer associated with a toolkit. If the renderer has not been used before, initialize it and store where it is. It will be re-used.
preambleSelector :: Toolkit -> Configuration -> Script Source #
The function that maps from configuration to the preamble.
parseExtraAttrs :: Toolkit -> Map Text Text -> Map Text Text Source #
Parse code block headers for extra attributes that are specific to this renderer. By default, no extra attributes are parsed.
availableToolkitsM :: PlotM [Toolkit] Source #
Monadic version of availableToolkits
.
Note that logging is disabled
unavailableToolkitsM :: PlotM [Toolkit] Source #
Monadic version of unavailableToolkits
data OutputSpec Source #
Internal description of all information needed to output a figure.
Constructors
OutputSpec | |
Fields
|
data Executable Source #
Executable program, and sometimes the directory where it can be found.
Constructors
Renderer | |
Fields
|
data ScriptResult Source #
Possible result of running a script
Constructors
ScriptSuccess | |
ScriptChecksFailed Text | |
ScriptFailure Text Int Script |
Instances
Show ScriptResult Source # | |
Defined in Text.Pandoc.Filter.Plot.Scripting Methods showsPrec :: Int -> ScriptResult -> ShowS # show :: ScriptResult -> String # showList :: [ScriptResult] -> ShowS # |
figurePath :: FigureSpec -> PlotM FilePath Source #
Determine the path a figure should have.
The path for this file is unique to the content of the figure,
so that figurePath
can be used to determine whether a figure should
be rendered again or not.
sourceCodePath :: FigureSpec -> PlotM FilePath Source #
Determine the path to the source code that generated the figure. To ensure that the source code path is distinguished from HTML figures, we use the extension .src.html.
data ParseFigureResult Source #
Constructors
NotAFigure | The block is not meant to become a figure |
PFigure FigureSpec | The block is meant to become a figure |
MissingToolkit Toolkit | The block is meant to become a figure, but the plotting toolkit is missing |
UnsupportedSaveFormat Toolkit SaveFormat | The block is meant to become a figure, but the figure format is incompatible with the plotting toolkit |
parseFigureSpec :: Block -> PlotM ParseFigureResult Source #
Determine inclusion specifications from Block
attributes.
If an environment is detected, but the save format is incompatible,
an error will be thrown.
plotToolkit :: Block -> Maybe Toolkit Source #
Determine which toolkit should be used to render the plot from a code block, if any.
captionReader :: Format -> Text -> Maybe [Inline] Source #
Reader a caption, based on input document format
configuration :: FilePath -> IO Configuration Source #
Read configuration from a YAML file. The keys are exactly the same as for code blocks.
If a key is not present, its value will be set to the default value. Parsing errors result in thrown exceptions.
defaultConfiguration :: Configuration Source #
Default configuration values.
Since: 0.5.0.0
configurationPathMeta :: Pandoc -> Maybe FilePath Source #
Extact path to configuration from the metadata in a Pandoc document.
The path to the configuration file should be under the plot-configuration
key.
In case there is no such metadata, return the default configuration.
For example, at the top of a markdown file:
--- title: My document author: John Doe plot-configuration: pathto/file.yml ---
The same can be specified via the command line using Pandoc's -M
flag:
pandoc --filter pandoc-plot -M plot-configuration="path/to/file.yml" ...
Since: 0.6.0.0
cleanOutputDirs :: Walkable Block b => Configuration -> b -> IO [FilePath] Source #
Clean all output related to pandoc-plot. This includes output directories specified in the configuration and in the document/block, as well as log files. Note that *all* files in pandoc-plot output directories will be removed.
The cleaned directories are returned.
outputDirs :: Walkable Block b => b -> PlotM [FilePath] Source #
Analyze a document to determine where would the pandoc-plot output directories be.
readDoc :: FilePath -> IO Pandoc Source #
Read a document, guessing what extensions and reader options are appropriate. If the file cannot be read for any reason, an error is thrown.
data FigureSpec Source #
Datatype containing all parameters required to specify a figure.
It is assumed that once a FigureSpec
has been created, no configuration
can overload it; hence, a FigureSpec
completely encodes a particular figure.
Constructors
FigureSpec | |
Fields
|
Verbosity of the logger.
Constructors
Debug | Log all messages, including debug messages. |
Info | Log information, warning, and error messages. |
Warning | Log warning and error messages. |
Error | Only log errors. |
Silent | Don't log anything. |
Instances
FromJSON Verbosity Source # | |
Defined in Text.Pandoc.Filter.Plot.Monad.Logging | |
IsString Verbosity Source # | |
Defined in Text.Pandoc.Filter.Plot.Monad.Logging Methods fromString :: String -> Verbosity # | |
Bounded Verbosity Source # | |
Enum Verbosity Source # | |
Defined in Text.Pandoc.Filter.Plot.Monad.Logging Methods succ :: Verbosity -> Verbosity # pred :: Verbosity -> Verbosity # fromEnum :: Verbosity -> Int # enumFrom :: Verbosity -> [Verbosity] # enumFromThen :: Verbosity -> Verbosity -> [Verbosity] # enumFromTo :: Verbosity -> Verbosity -> [Verbosity] # enumFromThenTo :: Verbosity -> Verbosity -> Verbosity -> [Verbosity] # | |
Show Verbosity Source # | |
Eq Verbosity Source # | |
Ord Verbosity Source # | |
Defined in Text.Pandoc.Filter.Plot.Monad.Logging |
liftIO :: MonadIO m => IO a -> m a #
Lift a computation from the IO
monad.
This allows us to run IO computations in any monadic stack, so long as it supports these kinds of operations
(i.e. IO
is the base monad for the stack).
Example
import Control.Monad.Trans.State -- from the "transformers" library printState :: Show s => StateT s IO () printState = do state <- get liftIO $ print state
Had we omitted
, we would have ended up with this error:liftIO
• Couldn't match type ‘IO’ with ‘StateT s IO’ Expected type: StateT s IO () Actual type: IO ()
The important part here is the mismatch between StateT s IO ()
and
.IO
()
Luckily, we know of a function that takes an
and returns an IO
a(m a)
:
,
enabling us to run the program and see the expected results:liftIO
> evalStateT printState "hello" "hello" > evalStateT printState 3 3
ask :: MonadReader r m => m r #
Retrieves the monad environment.
Arguments
:: MonadReader r m | |
=> (r -> a) | The selector function to apply to the environment. |
-> m a |
Retrieves a function of the current environment.
runCommand :: FilePath -> Text -> PlotM (ExitCode, Text) Source #
Run a command within the PlotM
monad. Stderr stream
is read and decoded, while Stdout is ignored.
Logging happens at the debug level if the command succeeds, or at
the error level if it does not succeed.
executable :: Toolkit -> PlotM Executable Source #
Find an executable.
data SaveFormat Source #
Generated figure file format supported by pandoc-plot. Note that not all formats are supported by all toolkits.
Constructors
PNG | Portable network graphics |
Portable document format | |
SVG | Scalable vector graphics |
JPG | JPEG/JPG compressed image |
EPS | Encapsulated postscript |
GIF | GIF format |
TIF | Tagged image format |
WEBP | WebP image format |
HTML | HTML for interactive plots. |
LaTeX | LaTeX text and pdf graphics |
Instances
data Configuration Source #
The Configuration
type holds the default values to use
when running pandoc-plot. These values can be overridden in code blocks.
You can create an instance of the Configuration
type from file using the configuration
function.
You can store the path to a configuration file in metadata under the key plot-configuration
. For example, in Markdown:
--- title: My document author: John Doe plot-configuration: pathtofile.yml ---
The same can be specified via the command line using Pandoc's -M
flag:
pandoc --filter pandoc-plot -M plot-configuration="path/to/file.yml" ...
In this case, use configurationPathMeta
to extact the path from Pandoc
documents.
Constructors
Configuration | |
Fields
|
Instances
Show Configuration Source # | |
Defined in Text.Pandoc.Filter.Plot.Monad Methods showsPrec :: Int -> Configuration -> ShowS # show :: Configuration -> String # showList :: [Configuration] -> ShowS # | |
Eq Configuration Source # | |
Defined in Text.Pandoc.Filter.Plot.Monad Methods (==) :: Configuration -> Configuration -> Bool # (/=) :: Configuration -> Configuration -> Bool # |
Description of the possible ways to sink log messages.
Enumeration of supported toolkits
Constructors
Matplotlib | |
Matlab | |
PlotlyPython | |
PlotlyR | |
Mathematica | |
Octave | |
GGPlot2 | |
GNUPlot | |
Graphviz | |
Bokeh | |
Plotsjl | |
PlantUML | |
SageMath | |
D2 | |
Asymptote | |
Mermaid |
Instances
Bounded Toolkit Source # | |||||
Enum Toolkit Source # | |||||
Generic Toolkit Source # | |||||
Defined in Text.Pandoc.Filter.Plot.Monad.Types Associated Types
| |||||
Show Toolkit Source # | This instance should only be used to display toolkit names | ||||
Eq Toolkit Source # | |||||
Ord Toolkit Source # | |||||
Defined in Text.Pandoc.Filter.Plot.Monad.Types | |||||
type Rep Toolkit Source # | |||||
Defined in Text.Pandoc.Filter.Plot.Monad.Types type Rep Toolkit = D1 ('MetaData "Toolkit" "Text.Pandoc.Filter.Plot.Monad.Types" "pandoc-plot-1.9.1-C6rJ4CAhwAW8roBsdze9eI" 'False) ((((C1 ('MetaCons "Matplotlib" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Matlab" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "PlotlyPython" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "PlotlyR" 'PrefixI 'False) (U1 :: Type -> Type))) :+: ((C1 ('MetaCons "Mathematica" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Octave" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "GGPlot2" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "GNUPlot" 'PrefixI 'False) (U1 :: Type -> Type)))) :+: (((C1 ('MetaCons "Graphviz" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Bokeh" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "Plotsjl" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "PlantUML" 'PrefixI 'False) (U1 :: Type -> Type))) :+: ((C1 ('MetaCons "SageMath" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "D2" 'PrefixI 'False) (U1 :: Type -> Type)) :+: (C1 ('MetaCons "Asymptote" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Mermaid" 'PrefixI 'False) (U1 :: Type -> Type))))) |
data RuntimeEnv Source #
asksConfig :: (Configuration -> a) -> PlotM a Source #
Get access to configuration within the PlotM
monad.
mapConcurrentlyN :: Traversable t => Int -> (a -> PlotM b) -> t a -> PlotM (t b) Source #
maps a function, performing at most N
actions concurrently.
throwStrictError :: Text -> PlotM () Source #
Throw an error that halts the execution of pandoc-plot due to a strict-mode.
data OutputSpec Source #
Internal description of all information needed to output a figure.
Constructors
OutputSpec | |
Fields
|
data Executable Source #
Executable program, and sometimes the directory where it can be found.
Constructors
Renderer | |
Fields
|
withPrependedPath :: FilePath -> PlotM a -> PlotM a Source #
Prepend a directory to the PATH environment variable for the duration of a computation.
This function is exception-safe; even if an exception happens during the computation, the PATH environment variable will be reverted back to its initial value.
fileHash :: FilePath -> PlotM FileHash Source #
Get a filehash. If the file hash has been computed before, it is reused. Otherwise, the filehash is calculated and stored.
data AvailabilityCheck Source #
Constructors
CommandSuccess (Executable -> Text) | |
ExecutableExists |
data CheckResult Source #
Result of checking scripts for problems
Constructors
CheckPassed | |
CheckFailed Text |
Instances
Monoid CheckResult Source # | |
Defined in Text.Pandoc.Filter.Plot.Monad.Types Methods mempty :: CheckResult # mappend :: CheckResult -> CheckResult -> CheckResult # mconcat :: [CheckResult] -> CheckResult # | |
Semigroup CheckResult Source # | |
Defined in Text.Pandoc.Filter.Plot.Monad.Types Methods (<>) :: CheckResult -> CheckResult -> CheckResult # sconcat :: NonEmpty CheckResult -> CheckResult # stimes :: Integral b => b -> CheckResult -> CheckResult # | |
Eq CheckResult Source # | |
Defined in Text.Pandoc.Filter.Plot.Monad.Types |
data InclusionKey Source #
Description of any possible inclusion key, both in documents and in configuration files.
Constructors
DirectoryK | |
CaptionK | |
SaveFormatK | |
WithSourceK | |
CaptionFormatK | |
PreambleK | |
DpiK | |
SourceCodeLabelK | |
StrictModeK | |
ExecutableK | |
CommandLineArgsK | |
DependenciesK | |
FileK | |
MatplotlibTightBBoxK | |
MatplotlibTransparentK |
Instances
Bounded InclusionKey Source # | |
Defined in Text.Pandoc.Filter.Plot.Monad.Types | |
Enum InclusionKey Source # | |
Defined in Text.Pandoc.Filter.Plot.Monad.Types Methods succ :: InclusionKey -> InclusionKey # pred :: InclusionKey -> InclusionKey # toEnum :: Int -> InclusionKey # fromEnum :: InclusionKey -> Int # enumFrom :: InclusionKey -> [InclusionKey] # enumFromThen :: InclusionKey -> InclusionKey -> [InclusionKey] # enumFromTo :: InclusionKey -> InclusionKey -> [InclusionKey] # enumFromThenTo :: InclusionKey -> InclusionKey -> InclusionKey -> [InclusionKey] # | |
Show InclusionKey Source # | Keys that pandoc-plot will look for in code blocks. These are only exported for testing purposes. |
Defined in Text.Pandoc.Filter.Plot.Monad.Types Methods showsPrec :: Int -> InclusionKey -> ShowS # show :: InclusionKey -> String # showList :: [InclusionKey] -> ShowS # | |
Eq InclusionKey Source # | |
Defined in Text.Pandoc.Filter.Plot.Monad.Types |
extension :: SaveFormat -> String Source #
Save format file extension
inclusionKeys :: [InclusionKey] Source #
List of all keys related to pandoc-plot that can be specified in source material.
exeFromPath :: FilePath -> Executable Source #
pathToExe :: Executable -> FilePath Source #
Arguments
:: Format | text format of the caption |
-> FigureSpec | |
-> PlotM Block |
Convert a FigureSpec
to a Pandoc figure component.
Note that the script to generate figure files must still
be run in another function.