pandoc-plot-0.8.0.0: A Pandoc filter to include figures generated from code blocks using your plotting toolkit of choice.

Copyright(c) Laurent P René de Cotret 2020
LicenseGNU GPL, version 2 or above
Maintainerlaurent.decotret@outlook.com
Stabilityinternal
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Text.Pandoc.Filter.Plot.Internal

Contents

Description

This module re-exports internal pandoc-plot functionality. The external use of content from this module is discouraged.

Synopsis

Documentation

preambleSelector :: Toolkit -> Configuration -> Script Source #

The function that maps from configuration to the preamble.

supportedSaveFormats :: Toolkit -> [SaveFormat] Source #

Save formats supported by this renderer.

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.

command :: Toolkit -> OutputSpec -> PlotM Text Source #

Generate the appropriate command-line command to generate a figure. The executable will need to be found first, hence the IO monad.

capture :: Toolkit -> FigureSpec -> FilePath -> Script Source #

Script fragment required to capture a figure.

executable :: Toolkit -> PlotM FilePath Source #

Path to the executable of a toolkit. If the executable can be found, then it will be the full path to it.

toolkitAvailable :: Toolkit -> PlotM Bool Source #

Check if a toolkit is available, based on the current configuration

availableToolkits :: Configuration -> IO [Toolkit] Source #

List of toolkits available on this machine. The executables to look for are taken from the configuration.

availableToolkitsM :: PlotM [Toolkit] Source #

Monadic version of availableToolkits.

unavailableToolkits :: Configuration -> IO [Toolkit] Source #

List of toolkits not available on this machine. The executables to look for are taken from the configur

unavailableToolkitsM :: PlotM [Toolkit] Source #

Monadic version of unavailableToolkits

data OutputSpec Source #

Internal description of all information needed to output a figure.

Constructors

OutputSpec 

Fields

toImage Source #

Arguments

:: Format

text format of the caption

-> FigureSpec 
-> Block 

Convert a FigureSpec to a Pandoc block component. Note that the script to generate figure files must still be run in another function.

plotToolkit :: Block -> Maybe Toolkit Source #

Determine which toolkit should be used to render the plot from a code block, if any.

parseFigureSpec :: Block -> PlotM (Maybe FigureSpec) Source #

Determine inclusion specifications from Block attributes. If an environment is detected, but the save format is incompatible, an error will be thrown.

captionReader :: Format -> Text -> Maybe [Inline] Source #

Reader a caption, based on input document format

defaultReaderOptions :: ReaderOptions Source #

Default reader options, straight out of Text.Pandoc.Options

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.

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

defaultConfiguration :: Configuration Source #

Default configuration values.

Since: 0.5.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.

readDoc :: FilePath -> IO Pandoc Source #

Read document, guessing what extensions and reader options are appropriate. If the file cannot be read for any reason, an error is thrown.

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

type PlotM a = ReaderT RuntimeEnv IO a Source #

pandoc-plot monad

data RuntimeEnv Source #

Constructors

RuntimeEnv 

Fields

runPlotM :: Configuration -> PlotM a -> IO a Source #

Evaluate a PlotM action.

Running external commands

runCommand :: 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.

Logging

data Verbosity Source #

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.

data LogSink Source #

Description of the possible ways to sink log messages.

Constructors

StdErr

Standard error stream.

LogFile FilePath

Appended to file.

Instances
Eq LogSink Source # 
Instance details

Defined in Text.Pandoc.Filter.Plot.Monad.Logging

Methods

(==) :: LogSink -> LogSink -> Bool #

(/=) :: LogSink -> LogSink -> Bool #

Show LogSink Source # 
Instance details

Defined in Text.Pandoc.Filter.Plot.Monad.Logging

err :: Text -> PlotM () Source #

Lifting and other monadic operations

liftIO :: MonadIO m => IO a -> m a #

Lift a computation from the IO monad.

ask :: MonadReader r m => m r #

Retrieves the monad environment.

asks #

Arguments

:: MonadReader r m 
=> (r -> a)

The selector function to apply to the environment.

-> m a 

Retrieves a function of the current environment.

asksConfig :: (Configuration -> a) -> PlotM a Source #

Get access to configuration within the PlotM monad.

Base types

data Toolkit Source #

Enumeration of supported toolkits

Instances
Bounded Toolkit Source # 
Instance details

Defined in Text.Pandoc.Filter.Plot.Monad.Types

Enum Toolkit Source # 
Instance details

Defined in Text.Pandoc.Filter.Plot.Monad.Types

Eq Toolkit Source # 
Instance details

Defined in Text.Pandoc.Filter.Plot.Monad.Types

Methods

(==) :: Toolkit -> Toolkit -> Bool #

(/=) :: Toolkit -> Toolkit -> Bool #

Show Toolkit Source #

This instance should only be used to display toolkit names

Instance details

Defined in Text.Pandoc.Filter.Plot.Monad.Types

Generic Toolkit Source # 
Instance details

Defined in Text.Pandoc.Filter.Plot.Monad.Types

Associated Types

type Rep Toolkit :: Type -> Type #

Methods

from :: Toolkit -> Rep Toolkit x #

to :: Rep Toolkit x -> Toolkit #

type Rep Toolkit Source # 
Instance details

Defined in Text.Pandoc.Filter.Plot.Monad.Types

type Rep Toolkit = D1 (MetaData "Toolkit" "Text.Pandoc.Filter.Plot.Monad.Types" "pandoc-plot-0.8.0.0-KeIEPdhIrSU5fMbiqiw4wm" 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)))))

data FigureSpec Source #

Datatype containing all parameters required to run pandoc-plot.

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

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

PDF

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.

Instances
Bounded SaveFormat Source # 
Instance details

Defined in Text.Pandoc.Filter.Plot.Monad.Types

Enum SaveFormat Source # 
Instance details

Defined in Text.Pandoc.Filter.Plot.Monad.Types

Eq SaveFormat Source # 
Instance details

Defined in Text.Pandoc.Filter.Plot.Monad.Types

Show SaveFormat Source # 
Instance details

Defined in Text.Pandoc.Filter.Plot.Monad.Types

IsString SaveFormat Source # 
Instance details

Defined in Text.Pandoc.Filter.Plot.Monad.Types

Generic SaveFormat Source # 
Instance details

Defined in Text.Pandoc.Filter.Plot.Monad.Types

Associated Types

type Rep SaveFormat :: Type -> Type #

ToJSON SaveFormat Source # 
Instance details

Defined in Text.Pandoc.Filter.Plot.Monad.Types

FromJSON SaveFormat Source # 
Instance details

Defined in Text.Pandoc.Filter.Plot.Monad.Types

type Rep SaveFormat Source # 
Instance details

Defined in Text.Pandoc.Filter.Plot.Monad.Types

type Rep SaveFormat = D1 (MetaData "SaveFormat" "Text.Pandoc.Filter.Plot.Monad.Types" "pandoc-plot-0.8.0.0-KeIEPdhIrSU5fMbiqiw4wm" False) (((C1 (MetaCons "PNG" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "PDF" PrefixI False) (U1 :: Type -> Type)) :+: (C1 (MetaCons "SVG" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "JPG" PrefixI False) (U1 :: Type -> Type))) :+: ((C1 (MetaCons "EPS" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "GIF" PrefixI False) (U1 :: Type -> Type)) :+: (C1 (MetaCons "TIF" PrefixI False) (U1 :: Type -> Type) :+: (C1 (MetaCons "WEBP" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "HTML" PrefixI False) (U1 :: Type -> Type)))))

figureContentHash :: FigureSpec -> Int Source #

Hash of the content of a FigureSpec. Note that unlike usual hashes, two FigureSpec with the same figureContentHash does not mean that they are equal!

Not all parts of a FigureSpec are related to running code. For example, changing the caption should not require running the figure again.

cls :: Toolkit -> Text Source #

Class name which will trigger the filter

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.