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 <sunlin7.mail@gmail.com> Link: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=71484
This commit is contained in:
parent
9419dad48a
commit
3e4c89e556
12
lisp/org.el
12
lisp/org.el
|
@ -16981,10 +16981,11 @@ buffer boundaries with possible narrowing."
|
||||||
(t nil))))
|
(t nil))))
|
||||||
|
|
||||||
(defun org-image--align (link)
|
(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:
|
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'.
|
affiliated keyword `#+attr_org'.
|
||||||
- By the `#+attr_html' or `#+attr_latex` keywords with valid
|
- By the `#+attr_html' or `#+attr_latex` keywords with valid
|
||||||
`:center' or `:align' values.
|
`: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."
|
implies no special alignment."
|
||||||
(let ((par (org-element-lineage link 'paragraph)))
|
(let ((par (org-element-lineage link 'paragraph)))
|
||||||
;; Only align when image is not surrounded by paragraph text:
|
;; 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
|
(save-excursion
|
||||||
(goto-char (org-element-contents-begin par))
|
(goto-char (org-element-contents-begin par))
|
||||||
(skip-chars-forward "\t ")
|
(skip-chars-forward "\t ")
|
||||||
(point))) ;account for leading space
|
(point))) ;account for leading space
|
||||||
;before link
|
;before link
|
||||||
(<= (- (org-element-contents-end par)
|
(<= (- (org-element-contents-end par)
|
||||||
(org-element-end link))
|
(org-element-end link))
|
||||||
1)) ;account for trailing newline
|
1)) ;account for trailing newline
|
||||||
;at end of paragraph
|
;at end of paragraph
|
||||||
(save-match-data
|
(save-match-data
|
||||||
;; Look for a valid ":center t" or ":align left|center|right"
|
;; Look for a valid ":center t" or ":align left|center|right"
|
||||||
|
|
Loading…
Reference in New Issue