git.iko.soy/typeable/pandoc
on master help sign in
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

commit462c140eb6751bd7978bf74ebf3f38db3b0bd126 authorAlbert Krewinkel <albert@zeitkraut.de> dateFri 14 Oct 2016, 23:16 (10 years ago) parent49b0b67
2 files changed+7−3
src/Text/Pandoc/Readers/Org/Blocks.hs+1−3 tests/Tests/Readers/Org.hs+6
src/Text/Pandoc/Readers/Org/Blocks.hs+1−3
@@ -288,9 +288,7 @@ blockAttributes = try $ do
288288 let kvAttrs = foldl' (appendValues "ATTR_HTML") Nothing kv
289289 let name = lookup "NAME" kv
290290 let label = lookup "LABEL" kv
291− caption' <- maybe (return Nothing)
292− (fmap Just . parseFromString inlines)
293− caption
291+ caption' <- sequence (parseFromString inlines . (++ "\n") <$> caption)
294292 kvAttrs' <- parseFromString keyValues . (++ "\n") $ fromMaybe mempty kvAttrs
295293 return $ BlockAttributes
296294 { blockAttrName = name
tests/Tests/Readers/Org.hs+6
@@ -916,6 +916,12 @@ tests =
916916 ] =?>
917917 let attr = ("fig:myfig", mempty, mempty)
918918 in para (imageWith attr "blub.png" "fig:" "My figure")
919+
920+ , "Figure with empty caption" =:
921+ unlines [ "#+CAPTION:"
922+ , "[[file:guess.jpg]]"
923+ ] =?>
924+ para (image "guess.jpg" "fig:" "")
919925 ]
920926
921927 , "Footnote" =: