diff options
author | Laurent P. René de Cotret <laurent.decotret@outlook.com> | 2022-03-31 07:52:55 -0400 |
---|---|---|
committer | Laurent P. René de Cotret <laurent.decotret@outlook.com> | 2022-03-31 07:52:55 -0400 |
commit | f24a05dda9dac8e52dbbae99cb837a9eb9dde29e (patch) | |
tree | 0eb1bac7286a28d4477519d4330a9cb908acd287 | |
parent | ab50ac6ed882be1b4512746a604be7b76ed9f35b (diff) |
(#37) remove figure captions when caption is empty1.5.1
-rw-r--r-- | CHANGELOG.md | 4 | ||||
-rw-r--r-- | pandoc-plot.cabal | 2 | ||||
-rw-r--r-- | src/Text/Pandoc/Filter/Plot/Embed.hs | 11 | ||||
-rw-r--r-- | tests/Common.hs | 24 | ||||
-rw-r--r-- | tests/Main.hs | 1 |
5 files changed, 37 insertions, 5 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c75db7..b46af06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ pandoc-plot uses [Semantic Versioning](http://semver.org/spec/v2.0.0.html) +## Release 1.5.1 + +* Figures with no captions (and no link to the source script), will now be shown as an image, without figure numbering (#37). + ## Release 1.5.0 * Added support for [Sage](https://www.sagemath.org/) (#44). diff --git a/pandoc-plot.cabal b/pandoc-plot.cabal index b2ccfb6..28b7959 100644 --- a/pandoc-plot.cabal +++ b/pandoc-plot.cabal @@ -1,6 +1,6 @@ cabal-version: 2.2 name: pandoc-plot -version: 1.5.0 +version: 1.5.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 diff --git a/src/Text/Pandoc/Filter/Plot/Embed.hs b/src/Text/Pandoc/Filter/Plot/Embed.hs index 9fbcd5f..330ba5c 100644 --- a/src/Text/Pandoc/Filter/Plot/Embed.hs +++ b/src/Text/Pandoc/Filter/Plot/Embed.hs @@ -79,12 +79,15 @@ figure :: FilePath -> Inlines -> PlotM Block --- To render images as figures with captions, the target title --- must be "fig:" --- Janky? yes figure as fp caption' = return . head . toList . para $ - imageWith as (pack fp) "fig:" caption' + imageWith as (pack fp) title caption' + where + -- To render images as figures with captions, the target title + -- must be "fig:" + -- Janky? yes + -- In case there is no caption, make this an image instead of a figure + title = if caption' /= mempty then "fig:" else mempty -- TODO: also add the case where SVG plots can be -- embedded in HTML output diff --git a/tests/Common.hs b/tests/Common.hs index 16616a8..8e05e64 100644 --- a/tests/Common.hs +++ b/tests/Common.hs @@ -318,6 +318,30 @@ testMarkdownFormattingCaption2 tk = extractImageCaption _ = mempty ------------------------------------------------------------------------------- +-- Test that Markdown bold formatting in captions is correctly rendered +testFigureWithoutCaption :: Toolkit -> TestTree +testFigureWithoutCaption tk = + testCase "appropriately build an image if no caption" $ do + let postfix = unpack . cls $ tk + tempDir <- (</> "test-image-if-no-caption-" <> postfix) <$> getTemporaryDirectory + ensureDirectoryExistsAndEmpty tempDir + + -- Note that this test is fragile, in the sense that the expected result must be carefully + -- constructed + let cb = + addDirectory tempDir $ codeBlock tk (trivialContent tk) + fmt = B.Format "markdown" + result <- runPlotM Nothing (defaultTestConfig {captionFormat = fmt}) $ make cb + assertEqual "" (Just mempty) (extractTitle result) + where + extractTitle (B.Para blocks) = extractImageCaption . head $ blocks + extractTitle _ = Nothing + + extractImageCaption (Image _ _ (_, title)) = Just title + extractImageCaption _ = Nothing + + +------------------------------------------------------------------------------- -- Test that cleanOutpuDirs correctly cleans the output directory specified in a block. testCleanOutputDirs :: Toolkit -> TestTree testCleanOutputDirs tk = diff --git a/tests/Main.hs b/tests/Main.hs index e558cca..bf969e4 100644 --- a/tests/Main.hs +++ b/tests/Main.hs @@ -58,6 +58,7 @@ toolkitSuite tk = testOverrideConfiguration, testMarkdownFormattingCaption1, testMarkdownFormattingCaption2, + testFigureWithoutCaption, testCleanOutputDirs, testChecksFail ] |