-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A Pandoc filter to include figures generated from Python code blocks -- -- A Pandoc filter to include figures generated from Python code blocks. -- Keep the document and Python code in the same location. Output from -- Matplotlib is captured and included as a figure. @package pandoc-pyplot @version 2.1.2.0 -- | This module re-exports internal pandoc-pyplot functionality. module Text.Pandoc.Filter.Pyplot.Internal -- | Building configuration from a YAML file. The keys are exactly the same -- as for Markdown code blocks. -- -- If a key is either not present or unreadable, its value will be set to -- the default value. configuration :: FilePath -> IO Configuration -- | list of all keys related to pandoc-pyplot. inclusionKeys :: [String] -- | Keys that pandoc-pyplot will look for in code blocks. These are only -- exported for testing purposes. directoryKey :: String -- | Keys that pandoc-pyplot will look for in code blocks. These are only -- exported for testing purposes. captionKey :: String -- | Keys that pandoc-pyplot will look for in code blocks. These are only -- exported for testing purposes. dpiKey :: String -- | Keys that pandoc-pyplot will look for in code blocks. These are only -- exported for testing purposes. includePathKey :: String -- | Keys that pandoc-pyplot will look for in code blocks. These are only -- exported for testing purposes. saveFormatKey :: String -- | Datatype containing all parameters required to run pandoc-pyplot data FigureSpec FigureSpec :: String -> PythonScript -> SaveFormat -> FilePath -> Int -> Attr -> FigureSpec -- | Figure caption. [caption] :: FigureSpec -> String -- | Source code for the figure. [script] :: FigureSpec -> PythonScript -- | Save format of the figure [saveFormat] :: FigureSpec -> SaveFormat -- | Directory where to save the file [directory] :: FigureSpec -> FilePath -- | Dots-per-inch of figure [dpi] :: FigureSpec -> Int -- | Attributes not related to pandoc-pyplot will be propagated. [blockAttrs] :: FigureSpec -> Attr -- | Generated figure file format supported by pandoc-pyplot. data SaveFormat PNG :: SaveFormat PDF :: SaveFormat SVG :: SaveFormat JPG :: SaveFormat EPS :: SaveFormat GIF :: SaveFormat TIF :: SaveFormat -- | Parse an image save format string -- --
--   >>> saveFormatFromString ".png"
--   Just PNG
--   
-- --
--   >>> saveFormatFromString "jpeg"
--   Just JPEG
--   
-- --
--   >>> SaveFormatFromString "arbitrary"
--   Nothing
--   
saveFormatFromString :: String -> Maybe SaveFormat -- | Convert a FigureSpec to a Pandoc block component toImage :: FigureSpec -> Block -- | Determine the path to the source code that generated the figure. sourceCodePath :: FigureSpec -> FilePath -- | Determine the path a figure should have. figurePath :: FigureSpec -> FilePath -- | Modify a Python plotting script to save the figure to a filename. An -- additional file will also be captured. addPlotCapture :: FigureSpec -> PythonScript -- | Save format file extension extension :: SaveFormat -> String -- | Take a python script in string form, write it in a temporary -- directory, then execute it. runTempPythonScript :: String -> [String] -> PythonScript -> IO ScriptResult -- | Run the Python script. In case the file already exists, we can safely -- assume there is no need to re-run it. runScriptIfNecessary :: Configuration -> FigureSpec -> IO ScriptResult -- | String representation of a Python script type PythonScript = Text -- | Possible result of running a Python script data ScriptResult ScriptSuccess :: ScriptResult ScriptChecksFailed :: String -> ScriptResult ScriptFailure :: Int -> ScriptResult -- | Result of checking scripts for problems data CheckResult CheckPassed :: CheckResult CheckFailed :: String -> CheckResult -- | Possible errors returned by the filter data PandocPyplotError -- | Running Python script has yielded an error ScriptError :: Int -> PandocPyplotError -- | Python script did not pass all checks ScriptChecksFailedError :: String -> PandocPyplotError -- | Generated figure file format supported by pandoc-pyplot. data SaveFormat PNG :: SaveFormat PDF :: SaveFormat SVG :: SaveFormat JPG :: SaveFormat EPS :: SaveFormat GIF :: SaveFormat TIF :: SaveFormat -- | Parse an image save format string -- --
--   >>> saveFormatFromString ".png"
--   Just PNG
--   
-- --
--   >>> saveFormatFromString "jpeg"
--   Just JPEG
--   
-- --
--   >>> SaveFormatFromString "arbitrary"
--   Nothing
--   
saveFormatFromString :: String -> Maybe SaveFormat -- | Save format file extension extension :: SaveFormat -> String -- | Default interpreter should be Python 3, which has a different name on -- Windows ("python") vs Unix ("python3") defaultPlatformInterpreter :: String -- | Configuration of pandoc-pyplot, describing the default behavior of the -- filter. -- -- A Configuration is useful when dealing with lots of figures; it avoids -- repeating the same values.sta data Configuration Configuration :: FilePath -> PythonScript -> SaveFormat -> Int -> String -> [String] -> Configuration -- | The default directory where figures will be saved. [defaultDirectory] :: Configuration -> FilePath -- | The default script to run before other instructions. [defaultIncludeScript] :: Configuration -> PythonScript -- | The default save format of generated figures. [defaultSaveFormat] :: Configuration -> SaveFormat -- | The default dots-per-inch value for generated figures. [defaultDPI] :: Configuration -> Int -- | The name of the interpreter to use to render figures. [interpreter] :: Configuration -> String -- | Command-line flags to be passed to the Python interpreger, e.g. ["-O", -- "-Wignore"] [flags] :: Configuration -> [String] -- | Datatype containing all parameters required to run pandoc-pyplot data FigureSpec FigureSpec :: String -> PythonScript -> SaveFormat -> FilePath -> Int -> Attr -> FigureSpec -- | Figure caption. [caption] :: FigureSpec -> String -- | Source code for the figure. [script] :: FigureSpec -> PythonScript -- | Save format of the figure [saveFormat] :: FigureSpec -> SaveFormat -- | Directory where to save the file [directory] :: FigureSpec -> FilePath -- | Dots-per-inch of figure [dpi] :: FigureSpec -> Int -- | Attributes not related to pandoc-pyplot will be propagated. [blockAttrs] :: FigureSpec -> Attr -- | This module defines a Pandoc filter makePlot that can be used -- to walk over a Pandoc document and generate figures from Python code -- blocks. -- -- The syntax for code blocks is simple, Code blocks with the -- .pyplot attribute will trigger the filter. The code block -- will be reworked into a Python script and the output figure will be -- captured, along with a high-resolution version of the figure and the -- source code used to generate the figure. -- -- To trigger pandoc-pyplot, the following is required: -- -- -- -- Here are the possible attributes what pandoc-pyplot understands: -- -- -- -- Here are some example blocks in Markdown: -- --
--   This is a paragraph
--   
--   ```{.pyplot caption="This is a caption."}
--   import matplotlib.pyplot as plt
--   
--   plt.figure()
--   plt.plot([0,1,2,3,4], [1,2,3,4,5])
--   plt.title('This is an example figure')
--   ```
--   
--   This is another paragraph
--   
--   ```{.pyplot dpi=150 format=SVG}
--   # This example was taken from the Matplotlib gallery
--   # https://matplotlib.org/examples/pylab_examples/bar_stacked.html
--   
--   import numpy as np
--   import matplotlib.pyplot as plt
--   
--   N = 5
--   menMeans = (20, 35, 30, 35, 27)
--   womenMeans = (25, 32, 34, 20, 25)
--   menStd = (2, 3, 4, 1, 2)
--   womenStd = (3, 5, 2, 3, 3)
--   ind = np.arange(N)    # the x locations for the groups
--   width = 0.35       # the width of the bars: can also be len(x) sequence
--   
--   p1 = plt.bar(ind, menMeans, width, color='#d62728', yerr=menStd)
--   p2 = plt.bar(ind, womenMeans, width,
--                bottom=menMeans, yerr=womenStd)
--   
--   plt.ylabel(Scores)
--   plt.title('Scores by group and gender')
--   plt.xticks(ind, (G1, G2, G3, G4, G5))
--   plt.yticks(np.arange(0, 81, 10))
--   plt.legend((p1[0], p2[0]), (Men, Women))
--   ```
--   
-- -- This filter was originally designed to be used with Hakyll. In -- case you want to use the filter with your own Hakyll setup, you can -- use a transform function that works on entire documents: -- --
--   import Text.Pandoc.Filter.Pyplot (plotTransform)
--   
--   import Hakyll
--   
--   -- Unsafe compiler is required because of the interaction
--   -- in IO (i.e. running an external Python script).
--   makePlotPandocCompiler :: Compiler (Item String)
--   makePlotPandocCompiler =
--     pandocCompilerWithTransformM
--       defaultHakyllReaderOptions
--       defaultHakyllWriterOptions
--       (unsafeCompiler . plotTransform)
--   
-- -- Custom configurations are possible via the Configuration type -- and the filter functions plotTransformWithConfig and -- makePlotWithConfig. module Text.Pandoc.Filter.Pyplot -- | Highest-level function that can be walked over a Pandoc tree. All code -- blocks that have the '.pyplot' parameter will be considered figures. makePlot :: Block -> IO Block -- | like makePlot with with a custom default values. makePlotWithConfig :: Configuration -> Block -> IO Block -- | Walk over an entire Pandoc document, changing appropriate code blocks -- into figures. Default configuration is used. plotTransform :: Pandoc -> IO Pandoc -- | Walk over an entire Pandoc document, changing appropriate code blocks -- into figures. The default values are determined by a -- Configuration. plotTransformWithConfig :: Configuration -> Pandoc -> IO Pandoc -- | Building configuration from a YAML file. The keys are exactly the same -- as for Markdown code blocks. -- -- If a key is either not present or unreadable, its value will be set to -- the default value. configuration :: FilePath -> IO Configuration -- | Configuration of pandoc-pyplot, describing the default behavior of the -- filter. -- -- A Configuration is useful when dealing with lots of figures; it avoids -- repeating the same values.sta data Configuration Configuration :: FilePath -> PythonScript -> SaveFormat -> Int -> String -> [String] -> Configuration -- | The default directory where figures will be saved. [defaultDirectory] :: Configuration -> FilePath -- | The default script to run before other instructions. [defaultIncludeScript] :: Configuration -> PythonScript -- | The default save format of generated figures. [defaultSaveFormat] :: Configuration -> SaveFormat -- | The default dots-per-inch value for generated figures. [defaultDPI] :: Configuration -> Int -- | The name of the interpreter to use to render figures. [interpreter] :: Configuration -> String -- | Command-line flags to be passed to the Python interpreger, e.g. ["-O", -- "-Wignore"] [flags] :: Configuration -> [String] -- | String representation of a Python script type PythonScript = Text -- | Generated figure file format supported by pandoc-pyplot. data SaveFormat PNG :: SaveFormat PDF :: SaveFormat SVG :: SaveFormat JPG :: SaveFormat EPS :: SaveFormat GIF :: SaveFormat TIF :: SaveFormat -- | Possible errors returned by the filter data PandocPyplotError -- | Running Python script has yielded an error ScriptError :: Int -> PandocPyplotError -- | Python script did not pass all checks ScriptChecksFailedError :: String -> PandocPyplotError -- | Main routine to include Matplotlib plots. Code blocks containing the -- attributes .pyplot are considered Python plotting scripts. -- All other possible blocks are ignored. makePlot' :: Configuration -> Block -> IO (Either PandocPyplotError Block)