diff --git a/lisp/org.el b/lisp/org.el index ff5b63212..1698399c4 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -16981,10 +16981,11 @@ buffer boundaries with possible narrowing." (t nil)))) (defun org-image--align (link) - "Determine the alignment of the image link. + "Determine the alignment of the image LINK. +LINK is a link object. In decreasing order of priority, this is controlled: -- Per image by the value of `:center' or ``:align' in the +- Per image by the value of `:center' or `:align' in the affiliated keyword `#+attr_org'. - By the `#+attr_html' or `#+attr_latex` keywords with valid `:center' or `:align' values. @@ -16998,15 +16999,16 @@ will cause it to be right-aligned. A value of \"left\" or nil implies no special alignment." (let ((par (org-element-lineage link 'paragraph))) ;; Only align when image is not surrounded by paragraph text: - (when (and (= (org-element-begin link) + (when (and par ; when image is not in paragraph, but in table/headline/etc, do not align + (= (org-element-begin link) (save-excursion (goto-char (org-element-contents-begin par)) (skip-chars-forward "\t ") (point))) ;account for leading space ;before link (<= (- (org-element-contents-end par) - (org-element-end link)) - 1)) ;account for trailing newline + (org-element-end link)) + 1)) ;account for trailing newline ;at end of paragraph (save-match-data ;; Look for a valid ":center t" or ":align left|center|right"