From 462c140eb6751bd7978bf74ebf3f38db3b0bd126 Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Fri, 14 Oct 2016 23:16:51 +0200 Subject: Org reader: allow figure with empty caption A `#+CAPTION` attribute before an image is enough to turn an image into a figure. This wasn't the case because the `parseFromString` function, which processes the caption value, would fail on empty values. Adding a newline character to the caption value fixes this. Fixes: #3161 --- src/Text/Pandoc/Readers/Org/Blocks.hs | 4 +--- tests/Tests/Readers/Org.hs | 6 ++++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Text/Pandoc/Readers/Org/Blocks.hs b/src/Text/Pandoc/Readers/Org/Blocks.hs index d14c894e6..8d22beb33 100644 --- a/src/Text/Pandoc/Readers/Org/Blocks.hs +++ b/src/Text/Pandoc/Readers/Org/Blocks.hs @@ -288,9 +288,7 @@ blockAttributes = try $ do let kvAttrs = foldl' (appendValues "ATTR_HTML") Nothing kv let name = lookup "NAME" kv let label = lookup "LABEL" kv - caption' <- maybe (return Nothing) - (fmap Just . parseFromString inlines) - caption + caption' <- sequence (parseFromString inlines . (++ "\n") <$> caption) kvAttrs' <- parseFromString keyValues . (++ "\n") $ fromMaybe mempty kvAttrs return $ BlockAttributes { blockAttrName = name diff --git a/tests/Tests/Readers/Org.hs b/tests/Tests/Readers/Org.hs index 49423bd11..3eab710dc 100644 --- a/tests/Tests/Readers/Org.hs +++ b/tests/Tests/Readers/Org.hs @@ -916,6 +916,12 @@ tests = ] =?> let attr = ("fig:myfig", mempty, mempty) in para (imageWith attr "blub.png" "fig:" "My figure") + + , "Figure with empty caption" =: + unlines [ "#+CAPTION:" + , "[[file:guess.jpg]]" + ] =?> + para (image "guess.jpg" "fig:" "") ] , "Footnote" =: -- cgit v1.2.3