pandoc-plot 0.9.0.0 → 0.9.1.0
raw patch · 18 files changed
+160/−72 lines, 18 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Text.Pandoc.Filter.Plot: FileK :: InclusionKey
Files
- CHANGELOG.md +15/−0
- MANUAL.md +4/−4
- docs/MANUAL.html +13/−9
- executable/Main.hs +2/−4
- pandoc-plot.cabal +10/−1
- src/Text/Pandoc/Filter/Plot.hs +16/−7
- src/Text/Pandoc/Filter/Plot/Clean.hs +34/−13
- src/Text/Pandoc/Filter/Plot/Configuration.hs +7/−6
- src/Text/Pandoc/Filter/Plot/Internal.hs +0/−1
- src/Text/Pandoc/Filter/Plot/Monad.hs +4/−4
- src/Text/Pandoc/Filter/Plot/Monad/Logging.hs +6/−2
- src/Text/Pandoc/Filter/Plot/Monad/Types.hs +3/−1
- src/Text/Pandoc/Filter/Plot/Parse.hs +29/−14
- src/Text/Pandoc/Filter/Plot/Renderers.hs +0/−1
- src/Text/Pandoc/Filter/Plot/Renderers/Bokeh.hs +1/−1
- src/Text/Pandoc/Filter/Plot/Renderers/GNUPlot.hs +1/−1
- src/Text/Pandoc/Filter/Plot/Renderers/Matplotlib.hs +1/−1
- src/Text/Pandoc/Filter/Plot/Scripting.hs +14/−2
CHANGELOG.md view
@@ -2,6 +2,21 @@ pandoc-plot uses [Semantic Versioning](http://semver.org/spec/v2.0.0.html) +Release 0.9.1.0 +--------------- + +* Added the `file` parameter, which allows the user to read figure content from a file instead of using the code block content in documents. This is especially useful for complex figures, where you might want to have the help of your tooling in an IDE, for instance. Here's an example: + +````markdown + +```{.matplotlib file=myplot.py} +``` + +```` +* Better error messages when specifying logger verbosity. +* Cleaning output directories with `pandoc-plot clean` now follows configuration values for logging. +* Fixed an issue where configuration in metadata did not get parsed properly. + Release 0.9.0.0 ---------------
MANUAL.md view
@@ -2,8 +2,6 @@ The file MANUAL.md is automatically generated by the tools/mkmanual.ps1 script. Do not edit manually. --> -# pandoc-plot 0.9.0.0 - ## A Pandoc filter to generate figures from code blocks in documents `pandoc-plot` turns code blocks present in your documents (Markdown, LaTeX, etc.) into embedded figures, using your plotting toolkit of choice, including Matplotlib, ggplot2, MATLAB, Mathematica, and more. @@ -161,7 +159,7 @@ `pandoc-plot` is a command line executable with a few functions. You can take a look at the help using the `-h`/`--help` flag: ``` bash -pandoc-plot 0.9.0.0 - generate figures directly in documents +pandoc-plot 0.9.1.0 - generate figures directly in documents Usage: pandoc-plot.EXE [(-v|--version) | --full-version | (-m|--manual)] [COMMAND] [AST] @@ -240,7 +238,8 @@ source=(true|false) preamble=(path) dpi=(integer) - dependencies=[...] + dependencies=[...] + file=(path) executable=(path) caption_format=(text) } @@ -260,6 +259,7 @@ - `preamble` is a path to a script that will be included as a preamble to the content of the code block. This path is either absolute, or relative from the working directory where you call `pandoc-plot`. - `dpi` is the pixel density of the figure in dots-per-inch. Possible values are positive integers. Not all toolkits respect this. - `dependencies` is a list of files/directories that affect the figure, for example data files. If one of those files/directories changes, `pandoc-plot` will re-render the associated figure. Format is a comma-separated list, e.g. `dependencies=[data.txt, foo.bar, ~/wtv]`. Values for `dependencies` in the configuration file will be appended to the values in a code block. + - `file` is a path to a file from which to read the figure content. If this parameter is used, the content of the code block is ignored. By using this parameter, you can use all the standard tooling of your plotting toolkit of choice, which is especially useful for complex figures. - `executable` is a path to the executable to use (e.g. `C:\\python3.exe`) or the name of the executable (e.g. `python3`). - `caption_format` is the text format of the caption. Possible values are exactly the same as `pandoc`’s format specification, usually `FORMAT+EXTENSION-EXTENSION`. For example, captions in Markdown with raw LaTeX would be parsed correctly provided that `caption_format=markdown+raw_tex`. See Pandoc’s guide on [Specifying formats](https://pandoc.org/MANUAL.html#specifying-formats).
docs/MANUAL.html view
@@ -4,7 +4,7 @@ <meta charset="utf-8" /> <meta name="generator" content="pandoc" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" /> - <title>MANUAL</title> + <title>pandoc-plot 0.9.1.0 manual</title> <style> code{white-space: pre-wrap;} span.smallcaps{font-variant: small-caps;} @@ -82,10 +82,12 @@ <![endif]--> </head> <body> +<header id="title-block-header"> +<h1 class="title">pandoc-plot 0.9.1.0 manual</h1> +</header> <!-- The file MANUAL.md is automatically generated by the tools/mkmanual.ps1 script. Do not edit manually. --> -<h1 id="pandoc-plot-0.9.0.0">pandoc-plot 0.9.0.0</h1> <h2 id="a-pandoc-filter-to-generate-figures-from-code-blocks-in-documents">A Pandoc filter to generate figures from code blocks in documents</h2> <p><code>pandoc-plot</code> turns code blocks present in your documents (Markdown, LaTeX, etc.) into embedded figures, using your plotting toolkit of choice, including Matplotlib, ggplot2, MATLAB, Mathematica, and more.</p> <ul> @@ -185,7 +187,7 @@ <div class="sourceCode" id="cb10"><pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true"></a><span class="ex">pandoc</span> --filter pandoc-plot --filter pandoc-crossref -i myfile.md -o myfile.html</span></code></pre></div> <h2 id="detailed-usage">Detailed usage</h2> <p><code>pandoc-plot</code> is a command line executable with a few functions. You can take a look at the help using the <code>-h</code>/<code>--help</code> flag:</p> -<div class="sourceCode" id="cb11"><pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true"></a><span class="ex">pandoc-plot</span> 0.9.0.0 - generate figures directly in documents</span> +<div class="sourceCode" id="cb11"><pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true"></a><span class="ex">pandoc-plot</span> 0.9.1.0 - generate figures directly in documents</span> <span id="cb11-2"><a href="#cb11-2" aria-hidden="true"></a></span> <span id="cb11-3"><a href="#cb11-3" aria-hidden="true"></a><span class="ex">Usage</span>: pandoc-plot.EXE [(-v<span class="kw">|</span><span class="ex">--version</span>) <span class="kw">|</span> <span class="ex">--full-version</span> <span class="kw">|</span> <span class="kw">(</span><span class="ex">-m</span><span class="kw">|</span><span class="ex">--manual</span><span class="kw">)</span>] </span> <span id="cb11-4"><a href="#cb11-4" aria-hidden="true"></a> [<span class="ex">COMMAND</span>] [AST]</span> @@ -237,12 +239,13 @@ <span id="cb16-6"><a href="#cb16-6" aria-hidden="true"></a><span class="in"> source=(true|false) </span></span> <span id="cb16-7"><a href="#cb16-7" aria-hidden="true"></a><span class="in"> preamble=(path) </span></span> <span id="cb16-8"><a href="#cb16-8" aria-hidden="true"></a><span class="in"> dpi=(integer)</span></span> -<span id="cb16-9"><a href="#cb16-9" aria-hidden="true"></a><span class="in"> dependencies=[...] </span></span> -<span id="cb16-10"><a href="#cb16-10" aria-hidden="true"></a><span class="in"> executable=(path) </span></span> -<span id="cb16-11"><a href="#cb16-11" aria-hidden="true"></a><span class="in"> caption_format=(text)</span></span> -<span id="cb16-12"><a href="#cb16-12" aria-hidden="true"></a><span class="in"> }</span></span> -<span id="cb16-13"><a href="#cb16-13" aria-hidden="true"></a><span class="in"> # script content</span></span> -<span id="cb16-14"><a href="#cb16-14" aria-hidden="true"></a><span class="in"> ```</span></span></code></pre></div> +<span id="cb16-9"><a href="#cb16-9" aria-hidden="true"></a><span class="in"> dependencies=[...]</span></span> +<span id="cb16-10"><a href="#cb16-10" aria-hidden="true"></a><span class="in"> file=(path)</span></span> +<span id="cb16-11"><a href="#cb16-11" aria-hidden="true"></a><span class="in"> executable=(path) </span></span> +<span id="cb16-12"><a href="#cb16-12" aria-hidden="true"></a><span class="in"> caption_format=(text)</span></span> +<span id="cb16-13"><a href="#cb16-13" aria-hidden="true"></a><span class="in"> }</span></span> +<span id="cb16-14"><a href="#cb16-14" aria-hidden="true"></a><span class="in"> # script content</span></span> +<span id="cb16-15"><a href="#cb16-15" aria-hidden="true"></a><span class="in"> ```</span></span></code></pre></div> <ul> <li><code>cls</code> must be one of the following: <code>matplotlib</code>, <code>matlabplot</code>, <code>plotly_python</code>, <code>plotly_r</code>, <code>mathplot</code>, <code>octaveplot</code>, <code>ggplot2</code>, <code>gnuplot</code>, <code>graphviz</code>, <code>bokeh</code>, <code>plotsjl</code>.</li> </ul> @@ -256,6 +259,7 @@ <li><code>preamble</code> is a path to a script that will be included as a preamble to the content of the code block. This path is either absolute, or relative from the working directory where you call <code>pandoc-plot</code>.</li> <li><code>dpi</code> is the pixel density of the figure in dots-per-inch. Possible values are positive integers. Not all toolkits respect this.</li> <li><code>dependencies</code> is a list of files/directories that affect the figure, for example data files. If one of those files/directories changes, <code>pandoc-plot</code> will re-render the associated figure. Format is a comma-separated list, e.g. <code>dependencies=[data.txt, foo.bar, ~/wtv]</code>. Values for <code>dependencies</code> in the configuration file will be appended to the values in a code block.</li> +<li><code>file</code> is a path to a file from which to read the figure content. If this parameter is used, the content of the code block is ignored. By using this parameter, you can use all the standard tooling of your plotting toolkit of choice, which is especially useful for complex figures.</li> <li><code>executable</code> is a path to the executable to use (e.g. <code>C:\\python3.exe</code>) or the name of the executable (e.g. <code>python3</code>).</li> <li><code>caption_format</code> is the text format of the caption. Possible values are exactly the same as <code>pandoc</code>’s format specification, usually <code>FORMAT+EXTENSION-EXTENSION</code>. For example, captions in Markdown with raw LaTeX would be parsed correctly provided that <code>caption_format=markdown+raw_tex</code>. See Pandoc’s guide on <a href="https://pandoc.org/MANUAL.html#specifying-formats">Specifying formats</a>.</li> </ul>
executable/Main.hs view
@@ -7,7 +7,7 @@ module Main where -import Control.Monad (join, forM_, when, msum) +import Control.Monad (join, when, msum) import Data.List (intersperse, (\\)) import Data.Text (unpack) @@ -257,9 +257,7 @@ -- (3) local .pandoc-plot.yml -- (4) default config conf <- maybe localConfig configuration $ firstJusts [configurationPathMeta doc, mfp] - putStrLn $ "Cleaning output directories for " <> fp - cleanedDirs <- cleanOutputDirs conf doc - forM_ cleanedDirs $ \d -> putStrLn $ "Removed directory " <> d + cleanOutputDirs conf doc >> return () where firstJusts :: [Maybe a] -> Maybe a firstJusts = msum
pandoc-plot.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.2 name: pandoc-plot -version: 0.9.0.0 +version: 0.9.1.0 synopsis: A Pandoc filter to include figures generated from code blocks using your plotting toolkit of choice. description: A Pandoc filter to include figures generated from code blocks. Keep the document and code in the same location. Output is captured and included as a figure. category: Text @@ -26,6 +26,12 @@ type: git location: https://github.com/LaurentRDC/pandoc-plot + +flag static + description: Statically-linked binary + manual: True + default: False + library exposed-modules: Text.Pandoc.Filter.Plot @@ -89,6 +95,9 @@ hs-source-dirs: executable ghc-options: -Wall -Wcompat -threaded -rtsopts -with-rtsopts=-N + -- Build static executables on Linux only + if flag(static) + ld-options: -static -pthread build-depends: base >= 4.11 && <5 , containers
src/Text/Pandoc/Filter/Plot.hs view
@@ -1,5 +1,4 @@ {-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE RecordWildCards #-} {-# LANGUAGE FlexibleContexts #-} {-| Module : $header$ @@ -45,13 +44,23 @@ Here are the possible attributes what pandoc-plot understands for ALL toolkits: - * @directory=...@ : Directory where to save the figure. - * @source=true|false@ : Whether or not to link the source code of this figure in the caption. Ideal for web pages, for example. Default is false. - * @format=...@: Format of the generated figure. This can be an extension or an acronym, e.g. @format=PNG@. - * @caption="..."@: Specify a plot caption (or alternate text). Format for captions is specified in the documentation for the @Configuration@ type. + * @directory=...@ : Directory where to save the figure. This path should be specified with + respect to the current working directory, and not with respect to the document. + * @source=true|false@ : Whether or not to link the source code of this figure in the caption. + Ideal for web pages, for example. Default is false. + * @format=...@: Format of the generated figure. This can be an extension or an acronym, + e.g. @format=PNG@. + * @caption="..."@: Specify a plot caption (or alternate text). Format + for captions is specified in the documentation for the @Configuration@ type. * @dpi=...@: Specify a value for figure resolution, or dots-per-inch. Certain toolkits ignore this. - * @dependencies=[...]@: Specify files/directories on which a figure depends, e.g. data file. Figures will be re-rendered if one of those file/directory changes. - * @preamble=...@: Path to a file to include before the code block. Ideal to avoid repetition over many figures. + * @dependencies=[...]@: Specify files/directories on which a figure depends, e.g. data file. + Figures will be re-rendered if one of those file/directory changes. These paths should + be specified with respect to the current working directory, and not with respect to the document. + * @preamble=...@: Path to a file to include before the code block. Ideal to avoid repetition over + many figures. + * @file=...@: Path to a file from which to read the content of the figure. The content of the + code block will be ignored. This path should be specified with respect to the current working + directory, and not with respect to the document. Default values for the above attributes are stored in the @Configuration@ datatype. These can be specified in a YAML file.
src/Text/Pandoc/Filter/Plot/Clean.hs view
@@ -14,6 +14,7 @@ module Text.Pandoc.Filter.Plot.Clean ( cleanOutputDirs + , outputDirs , readDoc ) where @@ -26,7 +27,7 @@ import Data.List (nub) import Data.Maybe (fromMaybe, catMaybes) -import Data.Text (Text) +import Data.Text (Text, pack) import qualified Data.Text.IO as Text import System.Directory (removePathForcibly) @@ -49,20 +50,40 @@ -- Note that *all* files in pandoc-plot output directories will be removed. -- -- The cleaned directories are returned. -cleanOutputDirs :: Walkable Block b => Configuration -> b -> IO [FilePath] -cleanOutputDirs conf doc = do - +cleanOutputDirs :: Walkable Block b + => Configuration -> b -> IO [FilePath] +cleanOutputDirs conf = runPlotM conf . cleanOutputDirsM + + +-- | Analyze a document to determine where would the pandoc-plot output directories be. +outputDirs :: Walkable Block b + => b -> PlotM [FilePath] +outputDirs = fmap (nub . catMaybes) + . sequence + . query (\b -> [parseFigureSpec b >>= return . fmap directory]) + + +-- PlotM version of @cleanOutputDirs@ +cleanOutputDirsM :: Walkable Block b + => b -> PlotM [FilePath] +cleanOutputDirsM doc = do + conf <- asksConfig id case logSink conf of - LogFile fp -> removePathForcibly fp - _ -> return () + LogFile path -> do + info $ "Removing log file " <> pack path + liftIO $ removePathForcibly path + _ -> return () - directories <- sequence $ query (\b -> [outputDir b]) doc - forM (nub . catMaybes $ directories) removeDir - where - outputDir b = runPlotM conf (parseFigureSpec b >>= return . fmap directory) - - removeDir :: FilePath -> IO FilePath - removeDir d = removePathForcibly d >> return d + directories <- outputDirs doc + + forM directories $ \fp -> do + info $ "Removing directory " <> pack fp + -- It is important to use `removePathForcibly` here, because it does + -- not throw exceptions if the directory doesn't exist. This means + -- we do not have to check in advance if directories are nested in our + -- list of directories. + liftIO $ removePathForcibly fp + return fp -- | Read a document, guessing what extensions and reader options are appropriate. If
src/Text/Pandoc/Filter/Plot/Configuration.hs view
@@ -1,7 +1,5 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} - - {-| Module : $header$ Copyright : (c) Laurent P René de Cotret, 2020 @@ -25,8 +23,10 @@ import Data.Yaml import Data.Yaml.Config (ignoreEnv, loadYamlSettings) -import Text.Pandoc.Definition (Format(..), Pandoc(..), MetaValue(..), lookupMeta) +import System.FilePath (normalise) +import Text.Pandoc.Definition (Format(..), Pandoc(..), MetaValue(..), Inline(..), lookupMeta) + import Text.Pandoc.Filter.Plot.Monad -- | Read configuration from a YAML file. The @@ -35,7 +35,7 @@ -- If a key is not present, its value will be set -- to the default value. Parsing errors result in thrown exceptions. configuration :: FilePath -> IO Configuration -configuration fp = (loadYamlSettings [fp] [] ignoreEnv) >>= renderConfig +configuration fp = (loadYamlSettings [normalise fp] [] ignoreEnv) >>= renderConfig -- | Default configuration values. @@ -107,8 +107,9 @@ configurationPathMeta (Pandoc meta _) = lookupMeta "plot-configuration" meta >>= getPath where - getPath (MetaString s) = Just (unpack s) - getPath _ = Nothing + getPath (MetaString t) = Just (unpack t) + getPath (MetaInlines [Str s]) = Just (unpack s) + getPath _ = Nothing -- We define a precursor type because preambles are best specified as file paths,
src/Text/Pandoc/Filter/Plot/Internal.hs view
@@ -1,4 +1,3 @@- {-| Module : $header$ Copyright : (c) Laurent P René de Cotret, 2020
src/Text/Pandoc/Filter/Plot/Monad.hs view
@@ -97,10 +97,10 @@ debug, err, warning, info :: Text -> PlotM () -debug = log "DEBUG| " Debug -err = log "ERROR| " Error -warning = log "WARN | " Warning -info = log "INFO | " Info +debug = log "DEBUG | " Debug +err = log "ERROR | " Error +warning = log "WARN | " Warning +info = log "INFO | " Info -- | General purpose logging.
src/Text/Pandoc/Filter/Plot/Monad/Logging.hs view
@@ -27,6 +27,7 @@ import Control.Monad (forever) import Data.Char (toLower) +import Data.List (intercalate) import Data.String (IsString(..)) import Data.Text (Text, unpack) import Data.Text.IO (hPutStr) @@ -42,7 +43,7 @@ | Warning -- ^ Log warning and error messages. | Error -- ^ Only log errors. | Silent -- ^ Don't log anything. - deriving (Eq, Ord, Show) + deriving (Eq, Ord, Show, Enum, Bounded) -- | Description of the possible ways to sink log messages. @@ -98,9 +99,12 @@ | ls == "warning" = Warning | ls == "error" = Error | ls == "debug" = Debug - | otherwise = error $ "Unrecognized verbosity " <> s + | otherwise = errorWithoutStackTrace $ mconcat ["Unrecognized verbosity '", s, "'. Valid choices are: " ] <> choices where ls = toLower <$> s + choices = intercalate ", " + $ fmap (fmap toLower . show) + $ enumFromTo minBound (maxBound::Verbosity) instance FromJSON Verbosity where parseJSON (String t) = pure $ fromString . unpack $ t
src/Text/Pandoc/Filter/Plot/Monad/Types.hs view
@@ -122,6 +122,7 @@ | DpiK | ExecutableK | DependenciesK + | FileK | MatplotlibTightBBoxK | MatplotlibTransparentK deriving (Bounded, Eq, Enum) @@ -138,6 +139,7 @@ show DpiK = "dpi" show ExecutableK = "executable" show DependenciesK = "dependencies" + show FileK = "file" show MatplotlibTightBBoxK = "tight_bbox" show MatplotlibTransparentK = "transparent" @@ -194,7 +196,7 @@ | s `elem` ["tif", "tiff", "TIF", "TIFF", ".tif", ".tiff"] = TIF | s `elem` ["webp", "WEBP", ".webp"] = WEBP | s `elem` ["html", "HTML", ".html"] = HTML - | otherwise = error $ + | otherwise = errorWithoutStackTrace $ mconcat [ s , " is not one of valid save format : " , mconcat $ intersperse ", " $ show <$> saveFormats
src/Text/Pandoc/Filter/Plot/Parse.hs view
@@ -1,8 +1,5 @@-{-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE RecordWildCards #-} -{-# LANGUAGE TemplateHaskell #-} {-| Module : $header$ @@ -27,7 +24,7 @@ import Data.Default (def) import Data.List (intersperse) import qualified Data.Map.Strict as Map -import Data.Maybe (fromMaybe, listToMaybe) +import Data.Maybe (fromMaybe, listToMaybe, isJust, fromJust) import Data.String (fromString) import Data.Text (Text, pack, unpack) import qualified Data.Text as T @@ -55,16 +52,11 @@ -- If an environment is detected, but the save format is incompatible, -- an error will be thrown. parseFigureSpec :: Block -> PlotM (Maybe FigureSpec) -parseFigureSpec block@(CodeBlock (id', classes, attrs) content) = do - let toolkit = plotToolkit block - case toolkit of - Nothing -> return Nothing - Just tk -> do - if not (cls tk `elem` classes) - then return Nothing - else Just <$> figureSpec tk - +parseFigureSpec block@(CodeBlock (id', classes, attrs) _) = + sequence $ fmap figureSpec + $ plotToolkit block >>= hasToolkit where + hasToolkit = \tk -> if cls tk `elem` classes then return tk else Nothing attrs' = Map.fromList attrs preamblePath = unpack <$> Map.lookup (tshow PreambleK) attrs' @@ -85,6 +77,9 @@ defSaveFmt = defaultSaveFormat conf defDPI = defaultDPI conf + -- Decide between reading from file or using document content + content <- parseContent block + let caption = Map.findWithDefault mempty (tshow CaptionK) attrs' withSource = fromMaybe defWithSource $ readBool <$> Map.lookup (tshow WithSourceK) attrs' script = mconcat $ intersperse "\n" [header, includeScript, content] @@ -107,6 +102,26 @@ parseFigureSpec _ = return Nothing +-- | Parse script content from a block, if possible. +-- The script content can either come from a file +-- or from the code block itself. If both are present, +-- the file is preferred. +parseContent :: Block -> PlotM Script +parseContent (CodeBlock (_, _, attrs) content) = do + let attrs' = Map.fromList attrs + mfile = normalise . unpack <$> Map.lookup (tshow FileK) attrs' + when (content /= mempty && isJust mfile) $ do + err $ mconcat [ + "Figure refers to a file (", pack $ fromJust mfile + , ") but also has content in the document.\nThe file content will be preferred." + ] + let loadFromFile fp = do + info $ "Loading figure content from " <> pack fp + liftIO $ TIO.readFile fp + maybe (return content) loadFromFile mfile +parseContent _ = return mempty + + -- | Determine which toolkit should be used to render the plot -- from a code block, if any. plotToolkit :: Block -> Maybe Toolkit @@ -137,7 +152,7 @@ readBool :: Text -> Bool readBool s | s `elem` ["True", "true", "'True'", "'true'", "1"] = True | s `elem` ["False", "false", "'False'", "'false'", "0"] = False - | otherwise = error $ unpack $ mconcat ["Could not parse '", s, "' into a boolean. Please use 'True' or 'False'"] + | otherwise = errorWithoutStackTrace $ unpack $ mconcat ["Could not parse '", s, "' into a boolean. Please use 'True' or 'False'"] -- | Parse a list of file dependencies such as /[foo.bar, hello.txt]/.
src/Text/Pandoc/Filter/Plot/Renderers.hs view
@@ -1,6 +1,5 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} - {-| Module : $header$ Copyright : (c) Laurent P René de Cotret, 2020
src/Text/Pandoc/Filter/Plot/Renderers/Bokeh.hs view
@@ -74,4 +74,4 @@ HTML -> [st|save(__current_model, filename=r"#{fname}", resources=CDN)|] SVG -> [st|__current_model.output_backend="svg"; export_svgs(__current_model, filename=r"#{fname}")|] PNG -> [st|export_png(obj = __current_model, filename=r"#{fname}")|] - fmt -> error $ "Save format not supported: " <> show fmt + fmt -> errorWithoutStackTrace $ "Save format not supported: " <> show fmt
src/Text/Pandoc/Filter/Plot/Renderers/GNUPlot.hs view
@@ -52,4 +52,4 @@ terminalString GIF = "gif" terminalString JPG = "jpeg" terminalString PDF = "pdfcairo" -terminalString fmt = error $ "gnuplot: unsupported save format" <> show fmt +terminalString fmt = errorWithoutStackTrace $ "gnuplot: unsupported save format" <> show fmt
src/Text/Pandoc/Filter/Plot/Renderers/Matplotlib.hs view
@@ -84,4 +84,4 @@ readBool :: Text -> Bool readBool s | s `elem` ["True", "true", "'True'", "'true'", "1"] = True | s `elem` ["False", "false", "'False'", "'false'", "0"] = False - | otherwise = error $ unpack $ mconcat ["Could not parse '", s, "' into a boolean. Please use 'True' or 'False'"] + | otherwise = errorWithoutStackTrace $ unpack $ mconcat ["Could not parse '", s, "' into a boolean. Please use 'True' or 'False'"]
src/Text/Pandoc/Filter/Plot/Scripting.hs view
@@ -1,4 +1,3 @@-{-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} {-| @@ -25,6 +24,8 @@ import Data.Text (Text, pack, unpack) import qualified Data.Text.IO as T +import Paths_pandoc_plot (version) + import System.Directory (createDirectoryIfMissing, doesFileExist, getTemporaryDirectory) import System.Exit (ExitCode (..)) @@ -141,7 +142,18 @@ figureContentHash :: FigureSpec -> PlotM Word figureContentHash FigureSpec{..} = do dependenciesHash <- sequence $ fileHash <$> dependencies - return $ fromIntegral $ hash (fromEnum toolkit, script, fromEnum saveFormat, directory, dpi, dependenciesHash, extraAttrs) + -- hash looks strange because instances only exist for 7-tuples or less + return $ fromIntegral + $ hash ( (fromEnum toolkit + , script + , fromEnum saveFormat + , directory) + , ( dpi + , dependenciesHash + , extraAttrs + , show version -- Included version because capture + ) -- scripts may change between releases + ) -- | Determine the path a figure should have.