From 7d9d77ca44afa0c69abfefe07d7b027f81c8f1a0 Mon Sep 17 00:00:00 2001
From: John MacFarlane <jgm@berkeley.edu>
Date: Tue, 27 Jun 2017 15:25:37 +0200
Subject: [PATCH] Require nonempty alt text for `implicit_figures`.

A figure with an empty caption doesn't make sense.

Closes #2844.
---
 MANUAL.txt                          | 15 +++++++--------
 src/Text/Pandoc/Readers/Markdown.hs |  3 ++-
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/MANUAL.txt b/MANUAL.txt
index b5cea779e..a5121dc2f 100644
--- a/MANUAL.txt
+++ b/MANUAL.txt
@@ -3227,17 +3227,16 @@ The link text will be used as the image's alt text:
 
 #### Extension: `implicit_figures` ####
 
-An image occurring by itself in a paragraph will be rendered as
-a figure with a caption.[^5] (In LaTeX, a figure environment will be
-used; in HTML, the image will be placed in a `div` with class
-`figure`, together with a caption in a `p` with class `caption`.)
-The image's alt text will be used as the caption.
+An image with nonempty alt text, occurring by itself in a
+paragraph, will be rendered as a figure with a caption.  The
+image's alt text will be used as the caption.
 
     ![This is the caption](/url/of/image.png)
 
-[^5]: This feature is not yet implemented for RTF, OpenDocument, or
-    ODT. In those formats, you'll just get an image in a paragraph by
-    itself, with no caption.
+How this is rendered depends on the output format. Some output
+formats (e.g. RTF) do not yet support figures.  In those
+formats, you'll just get an image in a paragraph by itself, with
+no caption.
 
 If you just want a regular inline image, just make sure it is not
 the only thing in the paragraph. One way to do this is to insert a
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index 31b51f237..49007ad35 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -1035,7 +1035,8 @@ para = try $ do
               result' <- result
               case B.toList result' of
                    [Image attr alt (src,tit)]
-                     | Ext_implicit_figures `extensionEnabled` exts ->
+                     | not (null alt) &&
+                       Ext_implicit_figures `extensionEnabled` exts ->
                         -- the fig: at beginning of title indicates a figure
                         return $ B.para $ B.singleton
                                $ Image attr alt (src,'f':'i':'g':':':tit)