>From d9c83a962c0ce26e3d7baf2a5b7a58ba054ef275 Mon Sep 17 00:00:00 2001 From: TEC Date: Mon, 27 Sep 2021 19:16:58 +0800 Subject: [PATCH 3/3] org: Support displaying X% width images * lisp/org.el (org-display-inline-image--width): Instead of interpreting an image :width of X% as X pixels, take it as X% of the text width of the buffer. --- lisp/org.el | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index d61e74572..829df8cae 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -16647,7 +16647,8 @@ (defun org-display-inline-image--width (link) - When `org-image-actual-width' is t, the image's pixel width is used. - When `org-image-actual-width' is a number, that value will is used. - When `org-image-actual-width' is nil or a list, the first :width attribute - set (if it exists) is used to set the image width. + set (if it exists) is used to set the image width. A width of X% is + divided by 100. If no :width attribute is given and `org-image-actual-width' is a list with a number as the car, then that number is used as the default value. If the value is a float between 0 and 2, it interpreted as that proportion @@ -16667,7 +16668,11 @@ (defun org-display-inline-image--width (link) (re-search-forward attr-re par-end t))) (string-to-number (match-string 1)))) (attr-width-val - (when attr-width (string-to-number attr-width))) + (cond + ((null attr-width) nil) + ((string-match-p "\\`[0-9.]+%") + (/ (string-to-number attr-width) 100.0)) + (t (string-to-number attr-width)))) ;; Fallback to `org-image-actual-width' if no explicit width is given. (width (or attr-width-val (car org-image-actual-width)))) (if (and (floatp width) (<= 0 width 2.0)) -- 2.33.0