From 3e4c89e55649f95cffbf70fcf64dcbc69760f96f Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Tue, 11 Jun 2024 12:42:28 +0200 Subject: [PATCH] org-image--align: Fix image alignment when image is not inside paragraph * lisp/org.el (org-image--align): Improve docstring. Do not try to align when image is not inside a paragraph. Reported-by: Lin Sun Link: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=71484 --- lisp/org.el | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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"