Hi, Emacs Org-mode maintainers,

`org-html-inline-image-p' returns non-nil for a link whose description
is only white space (e.g. "[[https://example.com][ ]]").  The containing
paragraph is then treated as a standalone image and wrapped in a figure
instead of a plain <p>.

----------------------------->8<----------------------------------
(org-export-string-as "[[https://example.com][ ]]" 'html t nil) =>

<div id=\"org16b5a1b\" class=\"figure\">
<p><a href=\"https://example.com\";>https://example.com</a></p>
</div>
----------------------------->8<----------------------------------

But we expect:

<p><a href=\"https://example.com\";>https://example.com</a></p>

For contrast, a non-blank description is handled correctly:

----------------------------->8<----------------------------------
(org-export-string-as "[[https://example.com][  x  ]]" 'html t nil)

<p>
<a href=\"https://example.com\";>  x  </a></p>
----------------------------->8<----------------------------------

In the `else' branch, `org-html-inline-image-p' tests for the absence of
a bad object rather than for the presence of exactly one image link:

----------------------------->8<----------------------------------
  (not
   (let ((link-count 0))
     (org-element-map (org-element-contents link)
         (cons 'plain-text org-element-all-objects)
       (lambda (obj)
         (pcase (org-element-type obj)
           (`plain-text (org-string-nw-p obj))
           (`link (if (= link-count 1) t
                    (cl-incf link-count)
                    (not (org-export-inline-image-p
                          obj (plist-get info :html-inline-image-rules)))))
           (_ t)))
       info t)))
----------------------------->8<----------------------------------

With a whitespace-only description, `(org-string-nw-p obj)' returns nil
for the plain-text elements, so `org-element-map' finds no bad elements
and returns nil.  Consequently `(not nil)' evaluates to t, allowing
"no link at all" to pass as a valid image.

The attached patch ensures that `link-count' must be exactly 1 after
checking the contents.

Regards.

Attachment: 0001-lisp-ox-html.el-Fix-inline-image-test-for-blank-desc.patch
Description: Binary data

Reply via email to