pandoc-plot 1.1.0 → 1.1.1
raw patch · 9 files changed
+67/−39 lines, 9 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Text.Pandoc.Filter.Plot.Internal: ScriptFailure :: Text -> Int -> ScriptResult
+ Text.Pandoc.Filter.Plot.Internal: ScriptFailure :: Text -> Int -> Script -> ScriptResult
Files
- CHANGELOG.md +6/−0
- MANUAL.md +12/−2
- docs/MANUAL.html +15/−5
- pandoc-plot.cabal +1/−1
- src/Text/Pandoc/Filter/Plot.hs +1/−1
- src/Text/Pandoc/Filter/Plot/Configuration.hs +1/−1
- src/Text/Pandoc/Filter/Plot/Renderers/PlantUML.hs +8/−7
- src/Text/Pandoc/Filter/Plot/Scripting.hs +20/−4
- stack.yaml +3/−18
CHANGELOG.md view
@@ -2,6 +2,12 @@ pandoc-plot uses [Semantic Versioning](http://semver.org/spec/v2.0.0.html) +Release 1.1.1 +------------- + +* Error messages now include the source script and line numbers. +* The executables are now built with Pandoc 2.12. Pandoc 2.11 is still supported. + Release 1.1.0 -------------
MANUAL.md view
@@ -170,7 +170,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.0.2.0 - generate figures directly in documents +pandoc-plot 1.1.1 - generate figures directly in documents Usage: pandoc-plot.EXE [(-v|--version) | --full-version | (-m|--manual)] [COMMAND] [AST] @@ -259,7 +259,7 @@ ``` ```` -- `cls` must be one of the following: `matplotlib`, `matlabplot`, `plotly_python`, `plotly_r`, `mathplot`, `octaveplot`, `ggplot2`, `gnuplot`, `graphviz`, `bokeh`, `plotsjl`. +- `cls` must be one of the following: `matplotlib`, `matlabplot`, `plotly_python`, `plotly_r`, `mathplot`, `octaveplot`, `ggplot2`, `gnuplot`, `graphviz`, `bokeh`, `plotsjl`, `plantuml` (*new in version 1.1.0*). All following parameters are optional, with their default values controlled by the [configuration](#configuration). @@ -457,6 +457,16 @@ # preamble: plotsjl.jl executable: julia command_line_arguments: + +plantuml: + # preamble: plantuml.txt + executable: java + command_line_arguments: -jar plantuml.jar + # On Linux, it you have `plantuml.jar` as an executable, you can also + # use the following configuration instead: + # plantuml: + # executable: plantuml + # command_line_arguments: ``` A file like the above sets the **default** values; you can still override them in documents directly.
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.0.2.0 manual</title> + <title>pandoc-plot 1.1.1 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.0.2.0 manual</h1> +<h1 class="title">pandoc-plot 1.1.1 manual</h1> </header> <!-- The file MANUAL.md is automatically generated by the tools/mkmanual.ps1 script. Do not edit manually. @@ -207,7 +207,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.0.2.0 <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.1.1 <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> @@ -268,7 +268,7 @@ <span id="cb16-15"><a href="#cb16-15" aria-hidden="true" tabindex="-1"></a><span class="in"> # script content</span></span> <span id="cb16-16"><a href="#cb16-16" aria-hidden="true" tabindex="-1"></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> +<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>, <code>plantuml</code> (<em>new in version 1.1.0</em>).</li> </ul> <p>All following parameters are optional, with their default values controlled by the <a href="#configuration">configuration</a>.</p> <ul> @@ -436,7 +436,17 @@ <span id="cb22-122"><a href="#cb22-122" aria-hidden="true" tabindex="-1"></a><span class="fu">plotsjl</span><span class="kw">:</span></span> <span id="cb22-123"><a href="#cb22-123" aria-hidden="true" tabindex="-1"></a><span class="co"> # preamble: plotsjl.jl</span></span> <span id="cb22-124"><a href="#cb22-124" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">executable</span><span class="kw">:</span><span class="at"> julia</span></span> -<span id="cb22-125"><a href="#cb22-125" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">command_line_arguments</span><span class="kw">:</span></span></code></pre></div> +<span id="cb22-125"><a href="#cb22-125" aria-hidden="true" tabindex="-1"></a><span class="at"> </span><span class="fu">command_line_arguments</span><span class="kw">:</span></span> +<span id="cb22-126"><a href="#cb22-126" aria-hidden="true" tabindex="-1"></a></span> +<span id="cb22-127"><a href="#cb22-127" aria-hidden="true" tabindex="-1"></a><span class="fu">plantuml</span><span class="kw">:</span></span> +<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-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> +<span id="cb22-135"><a href="#cb22-135" aria-hidden="true" tabindex="-1"></a><span class="co"> # command_line_arguments:</span></span></code></pre></div> <p>A file like the above sets the <strong>default</strong> values; you can still override them in documents directly.</p> <p>The easiest way to specify configuration for <code>pandoc-plot</code> is to place a <code>.pandoc-plot.yml</code> file in the current working directory. You can also specify a configuration file in document metadata, under the <code>plot-configuration</code> key. For example, in Markdown:</p> <div class="sourceCode" id="cb23"><pre class="sourceCode markdown"><code class="sourceCode markdown"><span id="cb23-1"><a href="#cb23-1" aria-hidden="true" tabindex="-1"></a><span class="co">---</span></span>
pandoc-plot.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.2 name: pandoc-plot -version: 1.1.0 +version: 1.1.1 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
src/Text/Pandoc/Filter/Plot.hs view
@@ -191,7 +191,7 @@ where -- Logging of errors has been taken care of in @runScriptIfNecessary@ handleResult :: FigureSpec -> ScriptResult -> PlotM (Either PandocPlotError Block) - handleResult _ (ScriptFailure msg code) = return $ Left (ScriptRuntimeError msg code) + handleResult _ (ScriptFailure cmd code _) = return $ Left (ScriptRuntimeError cmd code) handleResult _ (ScriptChecksFailed msg) = return $ Left (ScriptChecksFailedError msg) handleResult spec ScriptSuccess = asks envConfig >>= \c -> Right <$> toFigure (captionFormat c) spec
src/Text/Pandoc/Filter/Plot/Configuration.hs view
@@ -295,7 +295,7 @@ _graphvizPrec <- v .:? (cls Graphviz) .!= _graphvizPrec defaultConfigPrecursor _bokehPrec <- v .:? (cls Bokeh) .!= _bokehPrec defaultConfigPrecursor _plotsjlPrec <- v .:? (cls Plotsjl) .!= _plotsjlPrec defaultConfigPrecursor - _plantumlPrec <- v .:? (cls PlantUML ) .!= _plantumlPrec defaultConfigPrecursor + _plantumlPrec <- v .:? (cls PlantUML) .!= _plantumlPrec defaultConfigPrecursor return $ ConfigPrecursor {..} parseJSON _ = fail "Could not parse configuration."
src/Text/Pandoc/Filter/Plot/Renderers/PlantUML.hs view
@@ -19,8 +19,8 @@ where import Data.Char +import Data.Text (pack, replace) import System.FilePath (takeDirectory, takeFileName, (</>)) -import Data.Text (replace, pack) import Text.Pandoc.Filter.Plot.Renderers.Prelude plantuml :: PlotM (Maybe Renderer) @@ -57,8 +57,9 @@ normalizePath :: String -> String normalizePath = map f - where f '\\' = '/' - f x = x + where + f '\\' = '/' + f x = x plantumlAvailable :: PlotM Bool plantumlAvailable = do @@ -70,7 +71,7 @@ withPrependedPath dir $ asks envCWD >>= flip commandSuccess [st|#{exe} #{cmdargs} -h|] 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 {..} 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
src/Text/Pandoc/Filter/Plot/Scripting.hs view
@@ -25,6 +25,7 @@ import Data.Functor.Identity (Identity (..)) import Data.Hashable (hash) import Data.Text (Text, pack, unpack) +import qualified Data.Text as T import qualified Data.Text.IO as T import Paths_pandoc_plot (version) import System.Directory @@ -48,6 +49,7 @@ import Text.Pandoc.SelfContained (makeSelfContained) import Text.Pandoc.Templates import Text.Pandoc.Writers (writeHtml5String) +import Text.Printf (printf) -- Run script as described by the spec, only if necessary runScriptIfNecessary :: FigureSpec -> PlotM ScriptResult @@ -74,13 +76,27 @@ data ScriptResult = ScriptSuccess | ScriptChecksFailed Text -- Message - | ScriptFailure Text Int -- Command and exit code + | ScriptFailure Text Int Script -- Command, exit code, and source script instance Show ScriptResult where show ScriptSuccess = "Script success." show (ScriptChecksFailed msg) = unpack $ "Script checks failed: " <> msg - show (ScriptFailure msg ec) = mconcat ["Script failed with exit code ", show ec, " and the following message: ", unpack msg] + show (ScriptFailure cmd ec s) = mconcat ["Command \"", unpack cmd, "\" failed with exit code ", show ec, ". The script source was: \n\n", unpack . formatScript $ s, "\n"] +-- | Format a script to show in error messages +formatScript :: Script -> Text +formatScript s = T.unlines . fmap (\(n, l) -> formatLine n l) $ zip linenos (T.lines s) + where + nlines = length (T.lines s) + linenos = [1 .. nlines] + + -- No version of ceil in Prelude, so 1 + floor will have to do + maxdigits :: Int + maxdigits = 1 + floor (logBase 10 (fromIntegral nlines :: Double)) + + formatLine :: Int -> Text -> Text + formatLine n l = pack (printf ("%" <> show maxdigits <> "d") n) <> " > " <> l + -- Run script as described by the spec -- Checks are performed, according to the renderer -- Note that stdout from the script is suppressed, but not @@ -117,7 +133,7 @@ (ec, _) <- runCommand cwd command_ case ec of ExitSuccess -> return ScriptSuccess - ExitFailure code -> return $ ScriptFailure command_ code + ExitFailure code -> return $ ScriptFailure command_ code script -- | Determine the temp script path from Figure specifications -- Note that for certain renderers, the appropriate file extension @@ -159,7 +175,7 @@ dependenciesHash, extraAttrs, show version -- Included version because capture scripts may change between releases - ) + ) ) -- | Determine the path a figure should have.
stack.yaml view
@@ -1,27 +1,12 @@-resolver: nightly-2021-01-05 # GHC 8.10.3 - -compiler: ghc-8.10.4 +resolver: lts-17.5 # GHC 8.10.4 packages: - . extra-deps: -- pandoc-2.11.4 -- citeproc-0.3.0.5@sha256:c32a7676fe1b369f44b6601fdf926ca50a4f3c2768006e696bf624953b1ba2ca,5590 -- commonmark-0.1.1.3@sha256:e3af411216448fe61cc36d2d5dbffd85c9f714761f1a47ae0a9c611babf72ea7,3278 -- commonmark-extensions-0.2.0.4@sha256:6a437bcfa3c757af4262b71336513619990eafb5cfdc33e57a499c93ad225608,3184 -- commonmark-pandoc-0.2.0.1@sha256:529c6e2c6cabf61558b66a28123eafc1d90d3324be29819f59f024e430312c1f,1105 +- pandoc-2.12 +- hslua-module-path-0.1.0.1 # For development - git: https://github.com/owickstrom/pandoc-include-code.git commit: 89c8465549960872257da993a399d978a269d6a6 - -# Faster compilation. -# See here: -# https://downloads.haskell.org/ghc/latest/docs/html/users_guide/flags.html#miscellaneous-compiler-options -# and here: -# https://ghc.gitlab.haskell.org/ghc/doc/users_guide/runtime_control.html -# ghc-options: -# pandoc: -j "+RTS -A64m -RTS" -# pandoc-citeproc: -j "+RTS -A64m -RTS" -# $targets: -j "+RTS -A64m -RTS"