packages feed

pandoc-plot 1.2.3 → 1.3.0

raw patch · 22 files changed

+277/−185 lines, 22 filesdep ~textdep ~yamlPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: text, yaml

API changes (from Hackage documentation)

- Text.Pandoc.Filter.Plot.Internal: silence :: PlotM a -> PlotM a
- Text.Pandoc.Filter.Plot.Internal: whenStrict :: PlotM () -> PlotM ()
+ Text.Pandoc.Filter.Plot: IncompatibleSaveFormatError :: SaveFormat -> Toolkit -> PandocPlotError
+ Text.Pandoc.Filter.Plot: plotFilter :: Configuration -> Maybe Format -> Pandoc -> IO Pandoc
+ Text.Pandoc.Filter.Plot.Internal: UnsupportedSaveFormat :: Toolkit -> SaveFormat -> ParseFigureResult

Files

CHANGELOG.md view
@@ -2,6 +2,15 @@ 
 pandoc-plot uses [Semantic Versioning](http://semver.org/spec/v2.0.0.html)
 
+## Release 1.3.0
+
+* The executable `pandoc-plot` is now aware of final conversion format.
+* Added a new function, `plotFilter`, which is aware of the pandoc's final conversion format. This allows for better defaults and error messages.
+* Deprecated `plotTransform` in favour of `plotFilter`. `plotTransform` will be removed in the next major update (v2+).
+* Save formats incompatible with toolkits will now show an appropriate error.
+* The build system is now based on `cabal-install` rather than `stack`.
+* Fixed an issue where some types of PlantUML diagrams (e.g. Gantt charts) would not be exported correctly (#30).
+
 ## Release 1.2.3
 
 * Fixed an issue where MATLAB figures were not being saved in the right location (#27).
@@ -282,4 +291,4 @@ 
 ## Release 0.1.0.0
 
-* Initial release+* Initial release
MANUAL.md view
@@ -31,6 +31,8 @@         -   [Finding installed toolkits](#finding-installed-toolkits)
         -   [Cleaning output](#cleaning-output)
         -   [Configuration template](#configuration-template)
+    -   [As a Haskell library](#as-a-haskell-library)
+        -   [Usage with Hakyll](#usage-with-hakyll)
 -   [Warning](#warning)
 
 ## Features Overview
@@ -170,7 +172,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 1.1.1 - generate figures directly in documents
+pandoc-plot 1.3.0 - generate figures directly in documents
 
 Usage: pandoc-plot.EXE [(-v|--version) | --full-version | (-m|--manual)] 
                        [COMMAND] [AST]
@@ -245,7 +247,7 @@       .language
       directory=(path) 
       caption=(text) 
-      format=(PNG|PDF|SVG|JPG|EPS|GIF|TIF|WEBP|HTML) 
+      format=(PNG|PDF|SVG|JPG|EPS|GIF|TIF|WEBP|HTML|LATEX) 
       source=(true|True|false|False) 
       source_label=(text)
       preamble=(path) 
@@ -266,7 +268,7 @@ -   `language` specifies the programming language used in this block. This parameter is ignored by `pandoc-plot`, but your text editor may use it to highlight code. See [Code highlighting](#code-highlighting) below.
 -   `directory` is a path to the directory where the figure and source code will be saved. You cannot control the file name. This path is either absolute, or relative from the working directory where you call `pandoc-plot`.
 -   `caption` is the caption text. The format of the caption is specified in the `caption_format` parameter, described below.
--   `format` is the desired filetype for the resulting figure. Possible values for `format` are \[`PNG`, `PDF`, `SVG`, `JPG`, `EPS`, `GIF`, `TIF`, `WEBP`, `HTML`\]. Not all toolkits support all formats. See `pandoc-plot toolkits` for toolkit-specific information regarding save formats. The `HTML` format is special; it can produce standalone, offline, interactive plots. As such, it only makes sense to use this format when creating HTML documents.
+-   `format` is the desired filetype for the resulting figure. Possible values for `format` are \[`PNG`, `PDF`, `SVG`, `JPG`, `EPS`, `GIF`, `TIF`, `WEBP`, `HTML`, `LATEX`\]. Not all toolkits support all formats. See `pandoc-plot toolkits` for toolkit-specific information regarding save formats. The `HTML` format is special; it can produce standalone, offline, interactive plots. As such, it only makes sense to use this format when creating HTML documents. Similarly, the `LATEX` format is special; plots in the LaTeX format will be embedded in the document. Therefore, it only makes sense to use this format when creating LaTeX documents.
 -   `source` is a boolean toggle that determines whether the source code should be linked in the caption or not. Possible values are \[`true`, `True`, `false`, `False`\].
 -   `source_label` is the text that links to source code (if `source=true`). This is useful if you are writing text in a different language. The default is `source_label="Source Code"`. You might want to set this via the [configuration](#configuration) instead.
 -   `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`.
@@ -462,7 +464,7 @@   # preamble: plantuml.txt
   executable: java
   command_line_arguments: -jar plantuml.jar
-  # On Linux, it you have `plantuml.jar` as an executable, you can also
+  # On Linux, if you have `plantuml.jar` as an executable, you can also
   # use the following configuration instead:
   # plantuml:
   #   executable: plantuml
@@ -627,7 +629,35 @@   -h,--help                Show this help text
 ```
 
+### As a Haskell library
+
+To include the functionality of `pandoc-plot` in a Haskell package, you can use the `make` function (for single blocks) or `plotFilter` function (for entire documents). [Take a look at the documentation on Hackage](https://hackage.haskell.org/package/pandoc-plot).
+
+#### Usage 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:
+
+``` haskell
+import Text.Pandoc.Filter.Plot (plotFilter, defaultConfiguration)
+import Text.Pandoc.Definition (Pandoc, Format(..)) -- from pandoc-types
+import Hakyll
+
+plotFilter' :: Pandoc -> IO Pandoc
+plotFilter' = 
+  -- Notify pandoc-plot that the final conversion will be to HTML
+  -- This helps give better error messages and adjust default values
+  plotFilter defaultConfiguration (Just $ Format "html5") 
+
+-- Unsafe compiler is required because of the interaction
+-- in IO (i.e. running an external script).
+makePlotPandocCompiler :: Compiler (Item String)
+makePlotPandocCompiler = 
+  pandocCompilerWithTransformM
+    defaultHakyllReaderOptions
+    defaultHakyllWriterOptions
+    (unsafeCompiler . plotFilter')
+```
+
 ## Warning
 
-Do not run this filter on unknown documents. There is nothing in
-`pandoc-plot` that can stop a script from performing **evil actions**.
+Do not run this filter on unknown documents. There is nothing in `pandoc-plot` that can stop a script from performing **evil actions**.
README.md view
@@ -2,7 +2,7 @@ 
 ## A Pandoc filter to generate figures from code blocks in documents
 
-[![Hackage version](https://img.shields.io/hackage/v/pandoc-plot.svg)](http://hackage.haskell.org/package/pandoc-plot) [![Conda Version](https://anaconda.org/conda-forge/pandoc-plot/badges/version.svg)](https://anaconda.org/conda-forge/pandoc-plot) [![license](https://img.shields.io/badge/license-GPLv2+-lightgray.svg)](https://www.gnu.org/licenses/gpl.html) 
+[![license](https://img.shields.io/badge/license-GPLv2+-lightgray.svg)](https://www.gnu.org/licenses/gpl.html) 
 
 `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.
 
@@ -90,12 +90,16 @@ 
 ### Binaries and Installers
 
+[![Latest release](https://img.shields.io/github/v/release/LaurentRDC/pandoc-plot)](https://github.com/LaurentRDC/pandoc-plot/releases)
+
 Windows, Linux, and Mac OS binaries are available on the [GitHub release
 page](https://github.com/LaurentRDC/pandoc-plot/releases). There are
 also Windows installers.
 
 ### conda
 
+[![Conda Version](https://anaconda.org/conda-forge/pandoc-plot/badges/version.svg)](https://anaconda.org/conda-forge/pandoc-plot)
+
 Like `pandoc`, `pandoc-plot` is available as a package installable with
 [`conda`](https://docs.conda.io/en/latest/). [Click here to see the
 package page](https://anaconda.org/conda-forge/pandoc-plot).
@@ -106,8 +110,10 @@ conda install -c conda-forge pandoc-plot
 ```
 
-### Homebrew
+### Homebrew 
 
+[![homebrew version](https://img.shields.io/homebrew/v/pandoc-plot)](https://formulae.brew.sh/formula/pandoc-plot)
+
 `pandoc-plot` is available as a package via [`Homebrew`](https://brew.sh/). [Click here to see the package page](https://formulae.brew.sh/formula/pandoc-plot#default). 
 
 To install:
@@ -128,6 +134,8 @@ 
 ### Arch Linux
 
+[![AUR version](https://img.shields.io/aur/version/pandoc-plot-bin)](https://aur.archlinux.org/packages/pandoc-plot-bin/)
+
 You can install `pandoc-plot` from the [archlinux user repository](https://aur.archlinux.org/packages/pandoc-plot-bin/) as `pandoc-plot-bin`. You can install using e.g. `yay`:
 
 ```sh
@@ -136,6 +144,8 @@ 
 ### From Hackage/Stackage
 
+[![Hackage version](https://img.shields.io/hackage/v/pandoc-plot.svg)](http://hackage.haskell.org/package/pandoc-plot)
+
 `pandoc-plot` is available on
 [Hackage](http://hackage.haskell.org/package/pandoc-plot) and
 [Stackage](https://www.stackage.org/nightly/package/pandoc-plot). Using
@@ -143,24 +153,15 @@ 
 ``` bash
 cabal update
-cabal install pandoc-plot
-```
-
-or
-
-``` bash
-stack update
-stack install pandoc-plot
+cabal install
 ```
 
 ### From source
 
-Building from source can be done using
-[`stack`](https://docs.haskellstack.org/en/stable/README/) or
-[`cabal`](https://www.haskell.org/cabal/):
+Building from source can be done using [`cabal`](https://www.haskell.org/cabal/):
 
 ``` bash
 git clone https://github.com/LaurentRDC/pandoc-plot
 cd pandoc-plot
-stack install # Alternatively, `cabal install`
+cabal install # Alternatively, `stack install`
 ```
benchmark/bench.hs view
@@ -22,7 +22,7 @@     Verbosity (Silent),
     cleanOutputDirs,
     defaultConfiguration,
-    plotTransform,
+    plotFilter,
   )
 import Text.Pandoc.Filter.Plot.Internal (cls)
 
@@ -32,7 +32,7 @@     [ envWithCleanup (return ()) (\_ -> cleanupEnv) $ \_ ->
         bgroup
           "main"
-          [ bench "filter" $ nfIO (plotTransform plotConfig benchDoc)
+          [ bench "filter" $ nfIO (plotFilter plotConfig Nothing benchDoc)
           ]
     ]
 
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>pandoc-plot 1.1.1 manual</title>
+  <title>pandoc-plot 1.3.0 manual</title>
   <style>
     code{white-space: pre-wrap;}
     span.smallcaps{font-variant: small-caps;}
@@ -84,7 +84,7 @@ </head>
 <body>
 <header id="title-block-header">
-<h1 class="title">pandoc-plot 1.1.1 manual</h1>
+<h1 class="title">pandoc-plot 1.3.0 manual</h1>
 </header>
 <!--
 The file MANUAL.md is automatically generated by the tools/mkmanual.ps1 script. Do not edit manually.
@@ -128,7 +128,11 @@ <li><a href="#cleaning-output">Cleaning output</a></li>
 <li><a href="#configuration-template">Configuration template</a></li>
 </ul></li>
+<li><a href="#as-a-haskell-library">As a Haskell library</a>
+<ul>
+<li><a href="#usage-with-hakyll">Usage with Hakyll</a></li>
 </ul></li>
+</ul></li>
 <li><a href="#warning">Warning</a></li>
 </ul>
 <h2 id="features-overview">Features Overview</h2>
@@ -207,7 +211,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" tabindex="-1"></a><span class="ex">pandoc</span> <span class="at">--filter</span> pandoc-plot <span class="at">--filter</span> pandoc-crossref <span class="at">-i</span> myfile.md <span class="at">-o</span> 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" tabindex="-1"></a><span class="ex">pandoc-plot</span> 1.1.1 <span class="at">-</span> 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" tabindex="-1"></a><span class="ex">pandoc-plot</span> 1.3.0 <span class="at">-</span> generate figures directly in documents</span>
 <span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a></span>
 <span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a><span class="ex">Usage:</span> pandoc-plot.EXE [<span class="er">(</span><span class="ex">-v</span><span class="kw">|</span><span class="ex">--version</span><span class="kw">)</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 class="ex">]</span> </span>
 <span id="cb11-4"><a href="#cb11-4" aria-hidden="true" tabindex="-1"></a>                       <span class="ex">[COMMAND]</span> [AST]</span>
@@ -255,7 +259,7 @@ <span id="cb16-2"><a href="#cb16-2" aria-hidden="true" tabindex="-1"></a><span class="in">      .language</span></span>
 <span id="cb16-3"><a href="#cb16-3" aria-hidden="true" tabindex="-1"></a><span class="in">      directory=(path) </span></span>
 <span id="cb16-4"><a href="#cb16-4" aria-hidden="true" tabindex="-1"></a><span class="in">      caption=(text) </span></span>
-<span id="cb16-5"><a href="#cb16-5" aria-hidden="true" tabindex="-1"></a><span class="in">      format=(PNG|PDF|SVG|JPG|EPS|GIF|TIF|WEBP|HTML) </span></span>
+<span id="cb16-5"><a href="#cb16-5" aria-hidden="true" tabindex="-1"></a><span class="in">      format=(PNG|PDF|SVG|JPG|EPS|GIF|TIF|WEBP|HTML|LATEX) </span></span>
 <span id="cb16-6"><a href="#cb16-6" aria-hidden="true" tabindex="-1"></a><span class="in">      source=(true|True|false|False) </span></span>
 <span id="cb16-7"><a href="#cb16-7" aria-hidden="true" tabindex="-1"></a><span class="in">      source_label=(text)</span></span>
 <span id="cb16-8"><a href="#cb16-8" aria-hidden="true" tabindex="-1"></a><span class="in">      preamble=(path) </span></span>
@@ -275,7 +279,7 @@ <li><code>language</code> specifies the programming language used in this block. This parameter is ignored by <code>pandoc-plot</code>, but your text editor may use it to highlight code. See <a href="#code-highlighting">Code highlighting</a> below.</li>
 <li><code>directory</code> is a path to the directory where the figure and source code will be saved. You cannot control the file name. This path is either absolute, or relative from the working directory where you call <code>pandoc-plot</code>.</li>
 <li><code>caption</code> is the caption text. The format of the caption is specified in the <code>caption_format</code> parameter, described below.</li>
-<li><code>format</code> is the desired filetype for the resulting figure. Possible values for <code>format</code> are [<code>PNG</code>, <code>PDF</code>, <code>SVG</code>, <code>JPG</code>, <code>EPS</code>, <code>GIF</code>, <code>TIF</code>, <code>WEBP</code>, <code>HTML</code>]. Not all toolkits support all formats. See <code>pandoc-plot toolkits</code> for toolkit-specific information regarding save formats. The <code>HTML</code> format is special; it can produce standalone, offline, interactive plots. As such, it only makes sense to use this format when creating HTML documents.</li>
+<li><code>format</code> is the desired filetype for the resulting figure. Possible values for <code>format</code> are [<code>PNG</code>, <code>PDF</code>, <code>SVG</code>, <code>JPG</code>, <code>EPS</code>, <code>GIF</code>, <code>TIF</code>, <code>WEBP</code>, <code>HTML</code>, <code>LATEX</code>]. Not all toolkits support all formats. See <code>pandoc-plot toolkits</code> for toolkit-specific information regarding save formats. The <code>HTML</code> format is special; it can produce standalone, offline, interactive plots. As such, it only makes sense to use this format when creating HTML documents. Similarly, the <code>LATEX</code> format is special; plots in the LaTeX format will be embedded in the document. Therefore, it only makes sense to use this format when creating LaTeX documents.</li>
 <li><code>source</code> is a boolean toggle that determines whether the source code should be linked in the caption or not. Possible values are [<code>true</code>, <code>True</code>, <code>false</code>, <code>False</code>].</li>
 <li><code>source_label</code> is the text that links to source code (if <code>source=true</code>). This is useful if you are writing text in a different language. The default is <code>source_label=&quot;Source Code&quot;</code>. You might want to set this via the <a href="#configuration">configuration</a> instead.</li>
 <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>
@@ -442,7 +446,7 @@ <span id="cb22-128"><a href="#cb22-128" aria-hidden="true" tabindex="-1"></a><span class="co">  # preamble: plantuml.txt</span></span>
 <span id="cb22-129"><a href="#cb22-129" aria-hidden="true" tabindex="-1"></a><span class="at">  </span><span class="fu">executable</span><span class="kw">:</span><span class="at"> java</span></span>
 <span id="cb22-130"><a href="#cb22-130" aria-hidden="true" tabindex="-1"></a><span class="at">  </span><span class="fu">command_line_arguments</span><span class="kw">:</span><span class="at"> -jar plantuml.jar</span></span>
-<span id="cb22-131"><a href="#cb22-131" aria-hidden="true" tabindex="-1"></a><span class="co">  # On Linux, it you have `plantuml.jar` as an executable, you can also</span></span>
+<span id="cb22-131"><a href="#cb22-131" aria-hidden="true" tabindex="-1"></a><span class="co">  # On Linux, if you have `plantuml.jar` as an executable, you can also</span></span>
 <span id="cb22-132"><a href="#cb22-132" aria-hidden="true" tabindex="-1"></a><span class="co">  # use the following configuration instead:</span></span>
 <span id="cb22-133"><a href="#cb22-133" aria-hidden="true" tabindex="-1"></a><span class="co">  # plantuml:</span></span>
 <span id="cb22-134"><a href="#cb22-134" aria-hidden="true" tabindex="-1"></a><span class="co">  #   executable: plantuml</span></span>
@@ -537,8 +541,29 @@ <span id="cb35-5"><a href="#cb35-5" aria-hidden="true" tabindex="-1"></a>  <span class="ex">--path</span> FILE              Target location of the configuration file. Default is</span>
 <span id="cb35-6"><a href="#cb35-6" aria-hidden="true" tabindex="-1"></a>                           <span class="st">&quot;.example-pandoc-plot.yml&quot;</span></span>
 <span id="cb35-7"><a href="#cb35-7" aria-hidden="true" tabindex="-1"></a>  <span class="ex">-h,--help</span>                Show this help text</span></code></pre></div>
+<h3 id="as-a-haskell-library">As a Haskell library</h3>
+<p>To include the functionality of <code>pandoc-plot</code> in a Haskell package, you can use the <code>make</code> function (for single blocks) or <code>plotFilter</code> function (for entire documents). <a href="https://hackage.haskell.org/package/pandoc-plot">Take a look at the documentation on Hackage</a>.</p>
+<h4 id="usage-with-hakyll">Usage with Hakyll</h4>
+<p>In case you want to use the filter with your own Hakyll setup, you can use a transform function that works on entire documents:</p>
+<div class="sourceCode" id="cb36"><pre class="sourceCode haskell"><code class="sourceCode haskell"><span id="cb36-1"><a href="#cb36-1" aria-hidden="true" tabindex="-1"></a><span class="kw">import</span> <span class="dt">Text.Pandoc.Filter.Plot</span> (plotFilter, defaultConfiguration)</span>
+<span id="cb36-2"><a href="#cb36-2" aria-hidden="true" tabindex="-1"></a><span class="kw">import</span> <span class="dt">Text.Pandoc.Definition</span> (<span class="dt">Pandoc</span>, <span class="dt">Format</span>(..)) <span class="co">-- from pandoc-types</span></span>
+<span id="cb36-3"><a href="#cb36-3" aria-hidden="true" tabindex="-1"></a><span class="kw">import</span> <span class="dt">Hakyll</span></span>
+<span id="cb36-4"><a href="#cb36-4" aria-hidden="true" tabindex="-1"></a></span>
+<span id="cb36-5"><a href="#cb36-5" aria-hidden="true" tabindex="-1"></a><span class="ot">plotFilter&#39; ::</span> <span class="dt">Pandoc</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> <span class="dt">Pandoc</span></span>
+<span id="cb36-6"><a href="#cb36-6" aria-hidden="true" tabindex="-1"></a>plotFilter&#39; <span class="ot">=</span> </span>
+<span id="cb36-7"><a href="#cb36-7" aria-hidden="true" tabindex="-1"></a>  <span class="co">-- Notify pandoc-plot that the final conversion will be to HTML</span></span>
+<span id="cb36-8"><a href="#cb36-8" aria-hidden="true" tabindex="-1"></a>  <span class="co">-- This helps give better error messages and adjust default values</span></span>
+<span id="cb36-9"><a href="#cb36-9" aria-hidden="true" tabindex="-1"></a>  plotFilter defaultConfiguration (<span class="dt">Just</span> <span class="op">$</span> <span class="dt">Format</span> <span class="st">&quot;html5&quot;</span>) </span>
+<span id="cb36-10"><a href="#cb36-10" aria-hidden="true" tabindex="-1"></a></span>
+<span id="cb36-11"><a href="#cb36-11" aria-hidden="true" tabindex="-1"></a><span class="co">-- Unsafe compiler is required because of the interaction</span></span>
+<span id="cb36-12"><a href="#cb36-12" aria-hidden="true" tabindex="-1"></a><span class="co">-- in IO (i.e. running an external script).</span></span>
+<span id="cb36-13"><a href="#cb36-13" aria-hidden="true" tabindex="-1"></a><span class="ot">makePlotPandocCompiler ::</span> <span class="dt">Compiler</span> (<span class="dt">Item</span> <span class="dt">String</span>)</span>
+<span id="cb36-14"><a href="#cb36-14" aria-hidden="true" tabindex="-1"></a>makePlotPandocCompiler <span class="ot">=</span> </span>
+<span id="cb36-15"><a href="#cb36-15" aria-hidden="true" tabindex="-1"></a>  pandocCompilerWithTransformM</span>
+<span id="cb36-16"><a href="#cb36-16" aria-hidden="true" tabindex="-1"></a>    defaultHakyllReaderOptions</span>
+<span id="cb36-17"><a href="#cb36-17" aria-hidden="true" tabindex="-1"></a>    defaultHakyllWriterOptions</span>
+<span id="cb36-18"><a href="#cb36-18" aria-hidden="true" tabindex="-1"></a>    (unsafeCompiler <span class="op">.</span> plotFilter&#39;)</span></code></pre></div>
 <h2 id="warning">Warning</h2>
-<p>Do not run this filter on unknown documents. There is nothing in
-<code>pandoc-plot</code> that can stop a script from performing <strong>evil actions</strong>.</p>
+<p>Do not run this filter on unknown documents. There is nothing in <code>pandoc-plot</code> that can stop a script from performing <strong>evil actions</strong>.</p>
 </body>
 </html>
example-config.yml view
@@ -129,7 +129,7 @@   # preamble: plantuml.txt
   executable: java
   command_line_arguments: -jar plantuml.jar
-  # On Linux, it you have `plantuml.jar` as an executable, you can also
+  # On Linux, if you have `plantuml.jar` as an executable, you can also
   # use the following configuration instead:
   # plantuml:
   #   executable: plantuml
executable/Main.hs view
@@ -55,7 +55,7 @@     configuration,
     defaultConfiguration,
     pandocPlotVersion,
-    plotTransform,
+    plotFilter,
   )
 import Text.Pandoc.Filter.Plot.Internal
   ( Executable (..),
@@ -216,9 +216,9 @@ toJSONFilterWithConfig = do
   upToDatePandoc <- checkRuntimePandocVersion
   when upToDatePandoc $
-    toJSONFilter $ \doc -> do
+    toJSONFilter $ \mfmt doc -> do
       c <- maybe localConfig configuration (configurationPathMeta doc)
-      plotTransform c doc
+      plotFilter c mfmt doc
 
 -- | Check that the runtime version of Pandoc is at least 2.11. The return value
 -- indicates whether the Pandoc version is new enough or not.
pandoc-plot.cabal view
@@ -1,6 +1,6 @@ cabal-version:  2.2
 name:           pandoc-plot
-version:        1.2.3
+version:        1.3.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 
@@ -21,7 +21,6 @@     README.md
     MANUAL.md
     docs/MANUAL.html
-    stack.yaml
     example-config.yml
 
     data/srctemplate.html
@@ -43,17 +42,12 @@     tests/includes/plotly-python.py
     tests/includes/plotly-r.r
     tests/includes/plotsjl.jl
+    tests/includes/plantuml.txt
 
 source-repository head
     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
@@ -123,9 +117,6 @@     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
@@ -11,7 +11,7 @@ -- Stability   : unstable
 -- Portability : portable
 --
--- This module defines a Pandoc filter @plotTransform@ and related functions
+-- This module defines a Pandoc filter @plotFilter@ and related functions
 -- that can be used to walk over a Pandoc document and generate figures from
 -- code blocks, using a multitude of plotting toolkits.
 --
@@ -21,18 +21,29 @@ -- Here is an example, in Markdown, for a plot in MATLAB:
 --
 -- @
---     This is a paragraph.
+-- This is a paragraph.
+-- 
+-- ```{.matlabplot}
+-- figure()
+-- plot([1,2,3,4,5], [1,2,3,4,5], '-k')
+-- ```
+-- @
 --
---     ```{.matlabplot}
---     figure()
---     plot([1,2,3,4,5], [1,2,3,4,5], '-k')
---     ```
+-- or a using GNUPlot:
+--
 -- @
+-- ```{.gnuplot format=png caption="Sinusoidal function" source=true}
+-- sin(x)
+-- 
+-- set xlabel "x"
+-- set ylabel "y"
+-- ```
+-- @
 --
 -- The code block will be reworked into a script and the output figure will be captured. Optionally, the source code
 --  used to generate the figure will be linked in the caption.
 --
--- Here are the possible attributes what pandoc-plot understands for ALL toolkits:
+-- Here are /some/ of the possible attributes what pandoc-plot understands for ALL toolkits:
 --
 --     * @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.
@@ -52,21 +63,11 @@ --       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.
---
--- Here is an example code block which will render a figure using gnuplot, in Markdown:
---
--- @
---     ```{.gnuplot format=png caption="Sinusoidal function" source=true}
---     sin(x)
---
---     set xlabel "x"
---     set ylabel "y"
---     ```
--- @
+-- All attributes are described in the online documentation, linked on the home page. 
+
 module Text.Pandoc.Filter.Plot
   ( -- * Operating on whole Pandoc documents
+    plotFilter,
     plotTransform,
 
     -- * Cleaning output directories
@@ -99,12 +100,13 @@ where
 
 import Control.Concurrent (getNumCapabilities)
+import Control.Monad.Reader (when)
 import Data.Functor ((<&>))
 import Data.Map (singleton)
 import Data.Text (Text, pack, unpack)
 import Data.Version (Version)
 import Paths_pandoc_plot (version)
-import Text.Pandoc.Definition (Block, Meta (..), MetaValue (..), Pandoc (..))
+import Text.Pandoc.Definition (Block, Meta (..), Format, MetaValue (..), Pandoc (..))
 import Text.Pandoc.Filter.Plot.Internal
   ( Configuration (..),
     FigureSpec,
@@ -118,6 +120,7 @@     Toolkit (..),
     Verbosity (..),
     asks,
+    asksConfig,
     availableToolkits,
     cleanOutputDirs,
     configuration,
@@ -132,31 +135,61 @@     toFigure,
     toolkits,
     unavailableToolkits,
-    whenStrict,
   )
 import Text.Pandoc.Walk (walkM)
 
 -- | Walk over an entire Pandoc document, transforming appropriate code blocks
 -- into figures. This function will operate on blocks in parallel if possible.
 --
+-- If the target conversion format is known, then this function can provide better
+-- defaults and error messages. For example, hyperlinks to source code will only be created
+-- if the final target format supports it (e.g. HTML).
+--
 -- Failing to render a figure does not stop the filter, so that you may run the filter
 -- on documents without having all necessary toolkits installed. In this case, error
 -- messages are printed to stderr, and blocks are left unchanged.
-plotTransform ::
+--
+-- @since 1.3.0
+plotFilter ::
   -- | Configuration for default values
   Configuration ->
+  -- | Final converted format, if known
+  Maybe Format ->
   -- | Input document
   Pandoc ->
   IO Pandoc
-plotTransform conf (Pandoc meta blocks) = do
+plotFilter conf mfmt (Pandoc meta blocks) = do
   maxproc <- getNumCapabilities
-  -- TODO: make filter aware of target format
-  runPlotM Nothing conf $ do
+  runPlotM mfmt conf $ do
     debug $ mconcat ["Starting a new run, utilizing at most ", pack . show $ maxproc, " processes."]
     mapConcurrentlyN maxproc make blocks <&> Pandoc newMeta
   where
+    -- This variable is needed for pandoc's default LaTeX template,
+    -- so that graphicx gets used.
     newMeta = meta <> Meta (singleton "graphics" $ MetaBool True)
 
+-- | Walk over an entire Pandoc document, transforming appropriate code blocks
+-- into figures. This function will operate on blocks in parallel if possible.
+--
+-- Failing to render a figure does not stop the filter, so that you may run the filter
+-- on documents without having all necessary toolkits installed. In this case, error
+-- messages are printed to stderr, and blocks are left unchanged.
+--
+-- __Note that this function is DEPRECATED in favour of @plotFilter@. It will be 
+-- removed in the next major update (v2+).__
+plotTransform ::
+  -- | Configuration for default values
+  Configuration ->
+  -- | Input document
+  Pandoc ->
+  IO Pandoc
+{-# DEPRECATED plotTransform
+  [ "plotTransform has been deprecated in favour of plotFilter, which is aware of conversion format."
+  , "plotTransform will be removed in an upcoming major update."
+  ] 
+#-}
+plotTransform conf = plotFilter conf Nothing
+
 -- | The version of the pandoc-plot package.
 --
 -- @since 0.8.0.0
@@ -164,7 +197,8 @@ pandocPlotVersion = version
 
 -- | Try to process the block with `pandoc-plot`. If a failure happens (or the block)
--- was not meant to become a figure, return the block as-is unless running in strict mode.
+-- was not meant to become a figure, return the block as-is unless running in strict mode. 
+-- In strict mode, any failure (for example, due to a missing plotting toolkit) will halt execution.
 --
 -- New in version 1.2.0: this function will detect nested code blocks, for example in @Div@ blocks.
 make :: Block -> PlotM Block
@@ -174,6 +208,8 @@     onError b e = do
       whenStrict $ throwStrictError (pack . show $ e)
       return b
+    
+    whenStrict f = asksConfig strictMode >>= \s -> when s f
 
 -- | Try to process the block with `pandoc-plot`, documenting the error.
 -- This function does not transform code blocks nested in
@@ -185,6 +221,7 @@       NotAFigure -> return $ Right block
       Figure fs -> runScriptIfNecessary fs >>= handleResult fs
       MissingToolkit tk -> return $ Left $ ToolkitNotInstalledError tk
+      UnsupportedSaveFormat tk sv -> return $ Left $ IncompatibleSaveFormatError sv tk
   where
     -- Logging of errors has been taken care of in @runScriptIfNecessary@
     handleResult :: FigureSpec -> ScriptResult -> PlotM (Either PandocPlotError Block)
@@ -196,8 +233,10 @@   = ScriptRuntimeError Text Int
   | ScriptChecksFailedError Text
   | ToolkitNotInstalledError Toolkit
+  | IncompatibleSaveFormatError SaveFormat Toolkit
 
 instance Show PandocPlotError where
   show (ScriptRuntimeError _ exitcode) = "ERROR (pandoc-plot) The script failed with exit code " <> show exitcode <> "."
   show (ScriptChecksFailedError msg) = "ERROR (pandoc-plot) A script check failed with message: " <> unpack msg <> "."
   show (ToolkitNotInstalledError tk) = "ERROR (pandoc-plot) The " <> show tk <> " toolkit is required but not installed."
+  show (IncompatibleSaveFormatError tk sv) = "ERROR (pandoc-plot) Save format " <> show sv <> " not supported by the " <> show tk <> " toolkit." 
src/Text/Pandoc/Filter/Plot/Clean.hs view
@@ -67,7 +67,7 @@     hasDirectory (Figure fs) = Just $ directory fs
     hasDirectory _ = Nothing
 
--- PlotM version of @cleanOutputDirs@
+-- | PlotM version of @cleanOutputDirs@
 cleanOutputDirsM ::
   Walkable Block b =>
   b ->
@@ -102,11 +102,11 @@               bst readerOpts b
       )
 
--- Determine format based on file extension
+-- | Determine format based on file extension
 -- Note : this is exactly the heuristic used by pandoc here:
 -- https://github.com/jgm/pandoc/blob/master/src/Text/Pandoc/App/FormatHeuristics.hs
 --
--- However, this is not exported, so I must re-define it here.
+-- However, this is not exported, so it must be re-defined here.
 formatFromFilePath :: FilePath -> Maybe Text
 formatFromFilePath x =
   case takeExtension (map toLower x) of
src/Text/Pandoc/Filter/Plot/Configuration.hs view
@@ -102,11 +102,11 @@ -- For example, at the top of a markdown file:
 --
 -- @
---     ---
---     title: My document
---     author: John Doe
---     plot-configuration: /path/to/file.yml
---     ---
+-- ---
+-- title: My document
+-- author: John Doe
+-- plot-configuration: /path/to/file.yml
+-- ---
 -- @
 --
 -- The same can be specified via the command line using Pandoc's @-M@ flag:
src/Text/Pandoc/Filter/Plot/Monad.hs view
@@ -26,7 +26,6 @@     withPrependedPath,
 
     -- * Halting pandoc-plot
-    whenStrict,
     throwStrictError,
 
     -- * Getting file hashes
@@ -48,7 +47,6 @@     ask,
     asks,
     asksConfig,
-    silence,
 
     -- * Base types
     module Text.Pandoc.Filter.Plot.Monad.Types,
@@ -66,10 +64,9 @@ import Control.Exception.Lifted (bracket, bracket_)
 import Control.Monad.Reader
   ( MonadIO (liftIO),
-    MonadReader (ask, local),
+    MonadReader (ask),
     ReaderT (runReaderT),
     asks,
-    when,
   )
 import Control.Monad.State.Strict
   ( MonadState (get, put),
@@ -107,7 +104,7 @@ import Text.Pandoc.Definition (Format (..))
 import Text.Pandoc.Filter.Plot.Monad.Logging
   ( LogSink (..),
-    Logger (lVerbosity),
+    Logger,
     MonadLogger (..),
     Verbosity (..),
     debug,
@@ -134,10 +131,6 @@     envCWD :: FilePath
   }
 
--- | Modify the runtime environment to be silent.
-silence :: PlotM a -> PlotM a
-silence = local (\(RuntimeEnv f c l d) -> RuntimeEnv f c l {lVerbosity = Silent} d)
-
 -- | Get access to configuration within the @PlotM@ monad.
 asksConfig :: (Configuration -> a) -> PlotM a
 asksConfig f = asks (f . envConfig)
@@ -176,8 +169,8 @@   (ec, processOutput') <-
     liftIO $
       readProcessStderr $
-        -- For Julia specifically, if the line below is not there,
-        -- The following error is thrown on Windows:
+        -- For Julia specifically, if the line below is not there (`setStdin (byteStringInput "")`),
+        -- the following error is thrown on Windows:
         --    ERROR: error initializing stdin in uv_dup:
         --           Unknown system error 50 (Unknown system error 50 50)
         setStdin (byteStringInput "") $
@@ -230,11 +223,6 @@   strict msg
   logger <- askLogger
   liftIO $ terminateLogging logger >> exitFailure
-
--- | Conditional execution of a PlotM action if pandoc-plot is
--- run in strict mode.
-whenStrict :: PlotM () -> PlotM ()
-whenStrict f = asksConfig strictMode >>= \s -> when s f
 
 -- Plot state is used for caching.
 -- One part consists of a map of filepaths to hashes
src/Text/Pandoc/Filter/Plot/Monad/Types.hs view
@@ -210,7 +210,7 @@     HTML
   | -- | LaTeX text and pdf graphics
     LaTeX
-  deriving (Bounded, Enum, Eq, Show, Generic)
+  deriving (Bounded, Enum, Ord, Eq, Show, Generic)
 
 instance IsString SaveFormat where
   fromString s
src/Text/Pandoc/Filter/Plot/Parse.hs view
@@ -48,9 +48,15 @@ tshow = pack . show
 
 data ParseFigureResult
+  -- | The block is not meant to become a figure
   = NotAFigure
+  -- | The block is meant to become a figure
   | Figure FigureSpec
+  -- | The block is meant to become a figure, but the plotting toolkit is missing
   | MissingToolkit Toolkit
+  -- | The block is meant to become a figure, but the figure format is incompatible 
+  --   with the plotting toolkit
+  | UnsupportedSaveFormat Toolkit SaveFormat
 
 -- | Determine inclusion specifications from @Block@ attributes.
 -- If an environment is detected, but the save format is incompatible,
@@ -66,56 +72,63 @@       r <- renderer tk
       case r of
         Nothing -> do
-          let msg = mconcat ["Renderer for ", tshow tk, " needed but is not installed"]
-          warning msg
+          err $ mconcat ["Renderer for ", tshow tk, " needed but is not installed"]
           return $ MissingToolkit tk
-        Just r' -> do
-          Figure <$> figureSpec r'
+        Just r' -> figureSpec r'
   where
     attrs' = Map.fromList attrs
     preamblePath = unpack <$> Map.lookup (tshow PreambleK) attrs'
 
-    figureSpec :: Renderer -> PlotM FigureSpec
+    figureSpec :: Renderer -> PlotM ParseFigureResult
     figureSpec renderer_@Renderer {..} = do
       conf <- asks envConfig
       let toolkit = rendererToolkit
-      let extraAttrs' = parseExtraAttrs toolkit attrs'
-          header = rendererComment $ "Generated by pandoc-plot " <> (pack . showVersion) version
-          defaultPreamble = preambleSelector toolkit conf
+          saveFormat = maybe (defaultSaveFormat conf) (fromString . unpack) (Map.lookup (tshow SaveFormatK) attrs')
 
-      includeScript <-
-        maybe
-          (return defaultPreamble)
-          (liftIO . TIO.readFile)
-          preamblePath
-      let -- Filtered attributes that are not relevant to pandoc-plot
-          -- This presumes that inclusionKeys includes ALL possible keys, for all toolkits
-          filteredAttrs = filter (\(k, _) -> k `notElem` (tshow <$> inclusionKeys)) attrs
-          defWithSource = defaultWithSource conf
-          defSaveFmt = defaultSaveFormat conf
-          defDPI = defaultDPI conf
+      -- Check if the saveformat is compatible with the toolkit
+      if not (saveFormat `elem` rendererSupportedSaveFormats) 
+        then do
+          err $ pack $ mconcat ["Save format ", show saveFormat, " not supported by ", show toolkit]
+          return $ UnsupportedSaveFormat toolkit saveFormat
+        else do
+          let extraAttrs' = parseExtraAttrs toolkit attrs'
+              header = rendererComment $ "Generated by pandoc-plot " <> (pack . showVersion) version
+              defaultPreamble = preambleSelector toolkit conf
 
-      -- Decide between reading from file or using document content
-      content <- parseContent block
+          includeScript <-
+            maybe
+              (return defaultPreamble)
+              (liftIO . TIO.readFile)
+              preamblePath
+          let -- Filter attributes that are not relevant to pandoc-plot
+              -- This presumes that inclusionKeys includes ALL possible keys, for all toolkits
+              filteredAttrs = filter (\(k, _) -> k `notElem` (tshow <$> inclusionKeys)) attrs
+              defWithSource = defaultWithSource conf
+              defDPI = defaultDPI conf
 
-      let caption = Map.findWithDefault mempty (tshow CaptionK) attrs'
-          withSource = maybe defWithSource readBool (Map.lookup (tshow WithSourceK) attrs')
-          script = mconcat $ intersperse "\n" [header, includeScript, content]
-          saveFormat = maybe defSaveFmt (fromString . unpack) (Map.lookup (tshow SaveFormatK) attrs')
-          directory = makeValid $ unpack $ Map.findWithDefault (pack $ defaultDirectory conf) (tshow DirectoryK) attrs'
-          dpi = maybe defDPI (read . unpack) (Map.lookup (tshow DpiK) attrs')
-          extraAttrs = Map.toList extraAttrs'
-          blockAttrs = (id', filter (/= cls toolkit) classes, filteredAttrs)
+          -- Decide between reading from file or using document content
+          content <- parseContent block
 
-      let blockDependencies = parseFileDependencies $ fromMaybe mempty $ Map.lookup (tshow DependenciesK) attrs'
-          dependencies = defaultDependencies conf <> blockDependencies
+          let caption = Map.findWithDefault mempty (tshow CaptionK) attrs'
+              withSource = maybe defWithSource readBool (Map.lookup (tshow WithSourceK) attrs')
+              script = mconcat $ intersperse "\n" [header, includeScript, content]
+              directory = makeValid $ unpack $ Map.findWithDefault (pack $ defaultDirectory conf) (tshow DirectoryK) attrs'
+              dpi = maybe defDPI (read . unpack) (Map.lookup (tshow DpiK) attrs')
+              extraAttrs = Map.toList extraAttrs'
+              blockAttrs = (id', filter (/= cls toolkit) classes, filteredAttrs)
 
-      -- This is the first opportunity to check save format compatibility
-      _' <-
-        unless (saveFormat `elem` rendererSupportedSaveFormats) $
-          let msg = pack $ mconcat ["Save format ", show saveFormat, " not supported by ", show toolkit]
-           in err msg
-      return FigureSpec {..}
+          let blockDependencies = parseFileDependencies $ fromMaybe mempty $ Map.lookup (tshow DependenciesK) attrs'
+              dependencies = defaultDependencies conf <> blockDependencies
+
+          -- This is the first opportunity to check save format compatibility
+          _' <-
+            unless (saveFormat `elem` rendererSupportedSaveFormats) $
+              let msg = pack $ mconcat ["Save format ", show saveFormat, " not supported by ", show toolkit]
+              in err msg
+          
+          -- Ensure that the save format makes sense given the final conversion format, if known
+          return $ Figure (FigureSpec {..})
+-- Base case: block is not a CodeBlock
 parseFigureSpec _ = return NotAFigure
 
 -- | Parse script content from a block, if possible.
@@ -127,7 +140,7 @@   let attrs' = Map.fromList attrs
       mfile = normalise . unpack <$> Map.lookup (tshow FileK) attrs'
   when (content /= mempty && isJust mfile) $ do
-    err $
+    warning $
       mconcat
         [ "Figure refers to a file (",
           pack $ fromJust mfile,
src/Text/Pandoc/Filter/Plot/Renderers.hs view
@@ -38,6 +38,9 @@ import Data.Maybe (catMaybes, isJust)
 import Data.Text (Text, pack)
 import Text.Pandoc.Filter.Plot.Monad
+import Text.Pandoc.Filter.Plot.Monad.Logging
+  ( Logger (lVerbosity),
+  )
 import Text.Pandoc.Filter.Plot.Renderers.Bokeh
 import Text.Pandoc.Filter.Plot.Renderers.GGPlot2
 import Text.Pandoc.Filter.Plot.Renderers.GNUPlot
@@ -135,8 +138,7 @@ --
 -- Note that logging is disabled
 availableToolkitsM :: PlotM [Toolkit]
-availableToolkitsM = silence $
-  asNonStrict $ do
+availableToolkitsM = asNonStrictAndSilent $ do
     mtks <- forConcurrently toolkits $ \tk -> do
       available <- isJust <$> renderer tk
       if available
@@ -144,7 +146,7 @@         else return Nothing
     return $ catMaybes mtks
   where
-    asNonStrict = local (\(RuntimeEnv f c l d) -> RuntimeEnv f c {strictMode = False} l d)
+    asNonStrictAndSilent = local (\(RuntimeEnv f c l d) -> RuntimeEnv f (c{strictMode = False}) (l{lVerbosity = Silent}) d)
 
 -- | Monadic version of @unavailableToolkits@
 unavailableToolkitsM :: PlotM [Toolkit]
src/Text/Pandoc/Filter/Plot/Renderers/PlantUML.hs view
@@ -19,8 +19,7 @@ where
 
 import Data.Char
-import Data.Text (pack, replace)
-import System.FilePath (takeDirectory, takeFileName, (</>))
+import System.FilePath (takeDirectory, (</>))
 import Text.Pandoc.Filter.Plot.Renderers.Prelude
 
 plantuml :: PlotM (Maybe Renderer)
@@ -53,6 +52,9 @@ plantumlCommand cmdargs exe OutputSpec {..} =
   let fmt = fmap toLower . show . saveFormat $ oFigureSpec
       dir = takeDirectory oFigurePath
+    -- the command below works as long as the script name is the same basename
+    -- as the target figure path. E.g.: script basename of pandocplot123456789.txt
+    -- will result in pandocplot123456789.(extension)
    in [st|#{exe} #{cmdargs} -t#{fmt} -output "#{oCWD </> dir}" "#{normalizePath oScriptPath}"|]
 
 normalizePath :: String -> String
@@ -70,8 +72,7 @@       cmdargs <- asksConfig plantumlCmdArgs
       withPrependedPath dir $ asks envCWD >>= flip commandSuccess [st|#{exe} #{cmdargs} -h|]
 
+-- PlantUML export is entirely based on command-line arguments
+-- so there is no need to modify the script itself.
 plantumlCapture :: FigureSpec -> FilePath -> Script
-plantumlCapture FigureSpec {..} fp =
-  -- Only the filename is included in the script; we need to also pass the ABSOLUTE output directory
-  -- to the executable.
-  replace "@startuml" ("@startuml " <> pack (takeFileName fp)) script
+plantumlCapture FigureSpec {..} _ = script
src/Text/Pandoc/Filter/Plot/Scripting.hs view
@@ -38,7 +38,8 @@     normalise,
     replaceExtension,
     takeDirectory,
-    (</>),
+    (</>), 
+    takeBaseName,
   )
 import Text.Pandoc.Class (runPure)
 import Text.Pandoc.Definition (Block (CodeBlock), Pandoc (Pandoc))
@@ -138,14 +139,13 @@ -- Note that for certain renderers, the appropriate file extension
 -- is important.
 tempScriptPath :: FigureSpec -> PlotM FilePath
-tempScriptPath FigureSpec {..} = do
+tempScriptPath fs@FigureSpec {..} = do
   let ext = rendererScriptExtension renderer_
-  -- MATLAB will refuse to process files that don't start with
-  -- a letter
   -- Note that this hash is only so that we are running scripts from unique
   -- file names; it does NOT determine whether this figure should
   -- be rendered or not.
-  let hashedPath = "pandocplot" <> (show . abs . hash $ script) <> ext
+  fp <- figurePath fs
+  let hashedPath = takeBaseName fp <> ext
   liftIO $ (</> hashedPath) <$> getTemporaryDirectory
 
 -- | Determine the path to the source code that generated the figure.
@@ -185,7 +185,10 @@ figurePath spec = do
   fh <- figureContentHash spec
   let ext = extension . saveFormat $ spec
-      stem = flip addExtension ext . show $ fh
+      -- MATLAB will refuse to process files that don't start with
+      -- a letter so it is simplest to use filenames that start 
+      -- with "pandocplot" throughout
+      stem = flip addExtension ext . mappend "pandocplot" . show $ fh
   return $ normalise $ directory spec </> stem
 
 -- | Write the source code of a figure to an HTML file with appropriate syntax highlighting.
− stack.yaml
@@ -1,33 +0,0 @@-resolver: lts-17.9 # GHC 8.10.4
-compiler: ghc-9.0.1
-
-packages:
-- .
-
-extra-deps:
-- pandoc-2.14.0.1
-- hslua-module-path-0.1.0.1@sha256:1fe319f18315618491260c912e85b6f73e406499c8fe2fa505e59036a4ff78fd,2502
-- citeproc-0.4@sha256:e198157aec60dbce1e6c1e29592ec6ded69ee5a79ea6645164356bd89458953e,5602
-- commonmark-0.2@sha256:ee873331ff496060dd9becdfaf7f1f4e0fd0688463f5d1f61481a60ed661af45,3426
-- commonmark-extensions-0.2.1.2
-- commonmark-pandoc-0.2.1@sha256:7c5db787c15c7a80aa66f5874023386e9b07c134ce24ef9f3aaebe9f52b6f817,1151
-- haddock-library-1.10.0@sha256:2a6c239da9225951a5d837e1ce373faeeae60d1345c78dd0a0b0f29df30c4fe9,4098 
-- jira-wiki-markup-1.4.0@sha256:2fdb7b50bd270d7d388b31df1c746c2864326b68bdd44045323c4f81fd6d5283,3851 
-- texmath-0.12.3@sha256:7560c097a483e69af99d38aab590924f4b2ab066da35fc5b68c01accd8b65190,6570
-- unicode-collation-0.1.3@sha256:4e92a82fff19e26e1ee46d7c945b3a4939a32c0c7e6beadbff9a91f1e16b5295,5122
-- xml-conduit-1.9.1.1@sha256:7213a64462d669f5ca55534a78a9b19c1d3757a605756e1f5065fa7c611493c1,3010
-
-# Specifically for GHC 9+
-- basement-0.0.12
-- memory-0.16.0
-- hslua-1.3.0.1
-- cryptonite-0.29
-- unix-2.7.2.2@sha256:ddb8fc5d5eede81dfad7846eceb65267fe4cf8b4f324bc74542f694a32335ef2,3496
-- Cabal-3.4.0.0@sha256:74ca2bc93297dc20b291c8dc721055278aa4a7942b0b5aca86766d407e3cbe5f,30533
-- directory-1.3.6.2@sha256:6e5f3e0adfe94483d5754d97d741b7d23a5e085d47176075b1955d4fa78f37aa,2811      
-- process-1.6.11.0@sha256:472c51a8903b55b1b423e7e4050facd1dce5e323fd81e5953f02ca500bb9d58c,2819       
-- time-1.10@sha256:536801b30aa2ce66da07cb19847827662650907efb2af4c8bef0a6276445075f,5738
-
-# For development
-- git: https://github.com/owickstrom/pandoc-include-code.git
-  commit: 89c8465549960872257da993a399d978a269d6a6
tests/Common.hs view
@@ -6,6 +6,7 @@ import Control.Monad (unless, when)
 import Data.List (isInfixOf, isSuffixOf, (!!))
 import Data.Monoid ((<>))
+import qualified Data.Set as S
 import Data.String (fromString)
 import Data.Text (Text, pack, unpack)
 import qualified Data.Text as T
@@ -136,6 +137,26 @@       length <$> filter (isExtensionOf (extension fmt))
         <$> listDirectory tempDir
     assertEqual "" numberjpgFiles 1
+
+-------------------------------------------------------------------------------
+-- Test that the appropriate error is raised when trying to save figures
+-- in an incompatible format
+testSaveFormatIncompatibility :: Toolkit -> TestTree
+testSaveFormatIncompatibility tk = 
+  testCase "raises the appropriate error on save format incompatibility" $ do
+    let allSaveFormats = enumFromTo minBound maxBound :: [SaveFormat]
+        incompatibleFormats = S.toList $ S.difference (S.fromList allSaveFormats) (S.fromList $ supportedSaveFormats tk)
+    if null incompatibleFormats
+      then return ()
+      else do
+        let fmt = head incompatibleFormats
+            cb = addSaveFormat fmt $ codeBlock tk (trivialContent tk)
+
+        result <- runPlotM Nothing defaultTestConfig $ makeEither cb
+        let expectedCheck :: Either PandocPlotError a -> Bool
+            expectedCheck (Left (IncompatibleSaveFormatError fmt' tk')) = (fmt' == fmt) && (tk' == tk)
+            expectedCheck _ = False
+        assertBool "" (expectedCheck result)
 
 -------------------------------------------------------------------------------
 -- Test that it is possible to not render source links in captions
tests/Main.hs view
@@ -52,6 +52,7 @@       testNestedCodeBlocks,
       testFileInclusion,
       testSaveFormat,
+      testSaveFormatIncompatibility,
       testWithSource,
       testSourceLabel,
       testOverrideConfiguration,
@@ -72,7 +73,7 @@ 
 -- The example configuration is build by hand (to add comments)
 -- and it is embedded into the executable. Therefore, we must make sure it
--- is correctly parsed (and is therefore valid.)
+-- is correctly parsed (and is hence valid.)
 testExampleConfiguration :: TestTree
 testExampleConfiguration =
   testCase "example configuration is correctly parsed" $ do
tests/fixtures/.verbose-config.yml view
@@ -4,6 +4,7 @@   verbosity: debug
 
 matplotlib:
+  executable: "python"
   command_line_arguments: -Wa
 
 plotsjl:
+ tests/includes/plantuml.txt view