aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRahguzar2023-10-23 21:23:53 +0200
committerEli Zaretskii2023-11-25 12:54:13 +0200
commit88bd83d17839f6df259c1fc820fdea320545ec4b (patch)
tree07c0c566905927978026b47125567e14d9db8be5
parent9656fe03585077370b18c7ece2407e55df24a5fa (diff)
downloademacs-88bd83d17839f6df259c1fc820fdea320545ec4b.tar.gz
emacs-88bd83d17839f6df259c1fc820fdea320545ec4b.zip
Make some aspects of shr rendering customizable
* lisp/net/shr.el (shr-fill-text, shr-sup-raise-factor) (shr-sub-raise-factor, shr-image-ascent): New custom variables. (shr-fill-lines): Only fill if 'shr-fill-text' is non-nil. (shr-put-image): Use 'shr-image-ascent' as value of :ascent. (shr-rescale-image, shr-make-placeholder-image): Use 'shr-image-ascent'. (shr-tag-sup, shr-tag-sub): Use 'shr-sup/sub-raise-factor'. (Bug#66676)
-rw-r--r--lisp/net/shr.el42
1 files changed, 33 insertions, 9 deletions
diff --git a/lisp/net/shr.el b/lisp/net/shr.el
index 645e1cc51e5..4e551663e9d 100644
--- a/lisp/net/shr.el
+++ b/lisp/net/shr.el
@@ -163,6 +163,30 @@ the specpdl size. If nil, just give up."
163 :version "28.1" 163 :version "28.1"
164 :type 'boolean) 164 :type 'boolean)
165 165
166(defcustom shr-fill-text t
167 "Non-nil means to fill the text according to the width of the window.
168If nil, text is not filled, and `visual-line-mode' can be used to reflow text."
169 :version "30.1"
170 :type 'boolean)
171
172
173(defcustom shr-sup-raise-factor 0.2
174 "The value of raise property for superscripts.
175Should be a non-negative float number between 0 and 1."
176 :version "30.1"
177 :type 'float)
178
179(defcustom shr-sub-raise-factor -0.2
180 "The value of raise property for subscripts.
181Should be a non-positive float number between 0 and 1."
182 :version "30.1"
183 :type 'float)
184
185(defcustom shr-image-ascent 100
186 "The value to be used for :ascent property when inserting images."
187 :version "30.1"
188 :type 'integer)
189
166(defvar shr-content-function nil 190(defvar shr-content-function nil
167 "If bound, this should be a function that will return the content. 191 "If bound, this should be a function that will return the content.
168This is used for cid: URLs, and the function is called with the 192This is used for cid: URLs, and the function is called with the
@@ -741,7 +765,7 @@ size, and full-buffer size."
741 (or shr-current-font 'shr-text))))))))) 765 (or shr-current-font 'shr-text)))))))))
742 766
743(defun shr-fill-lines (start end) 767(defun shr-fill-lines (start end)
744 (if (<= shr-internal-width 0) 768 (if (or (not shr-fill-text) (<= shr-internal-width 0))
745 nil 769 nil
746 (save-restriction 770 (save-restriction
747 (narrow-to-region start end) 771 (narrow-to-region start end)
@@ -1063,11 +1087,11 @@ element is the data blob and the second element is the content-type."
1063 (start (point)) 1087 (start (point))
1064 (image (cond 1088 (image (cond
1065 ((eq size 'original) 1089 ((eq size 'original)
1066 (create-image data nil t :ascent 100 1090 (create-image data nil t :ascent shr-image-ascent
1067 :format content-type)) 1091 :format content-type))
1068 ((eq content-type 'image/svg+xml) 1092 ((eq content-type 'image/svg+xml)
1069 (when (image-type-available-p 'svg) 1093 (when (image-type-available-p 'svg)
1070 (create-image data 'svg t :ascent 100))) 1094 (create-image data 'svg t :ascent shr-image-ascent)))
1071 ((eq size 'full) 1095 ((eq size 'full)
1072 (ignore-errors 1096 (ignore-errors
1073 (shr-rescale-image data content-type 1097 (shr-rescale-image data content-type
@@ -1114,7 +1138,7 @@ The size of the displayed image will not exceed
1114MAX-WIDTH/MAX-HEIGHT. If not given, use the current window 1138MAX-WIDTH/MAX-HEIGHT. If not given, use the current window
1115width/height instead." 1139width/height instead."
1116 (if (not (get-buffer-window (current-buffer) t)) 1140 (if (not (get-buffer-window (current-buffer) t))
1117 (create-image data nil t :ascent 100) 1141 (create-image data nil t :ascent shr-image-ascent)
1118 (let* ((edges (window-inside-pixel-edges 1142 (let* ((edges (window-inside-pixel-edges
1119 (get-buffer-window (current-buffer)))) 1143 (get-buffer-window (current-buffer))))
1120 (max-width (truncate (* shr-max-image-proportion 1144 (max-width (truncate (* shr-max-image-proportion
@@ -1135,13 +1159,13 @@ width/height instead."
1135 (< (* height scaling) max-height)) 1159 (< (* height scaling) max-height))
1136 (create-image 1160 (create-image
1137 data (shr--image-type) t 1161 data (shr--image-type) t
1138 :ascent 100 1162 :ascent shr-image-ascent
1139 :width width 1163 :width width
1140 :height height 1164 :height height
1141 :format content-type) 1165 :format content-type)
1142 (create-image 1166 (create-image
1143 data (shr--image-type) t 1167 data (shr--image-type) t
1144 :ascent 100 1168 :ascent shr-image-ascent
1145 :max-width max-width 1169 :max-width max-width
1146 :max-height max-height 1170 :max-height max-height
1147 :format content-type))))) 1171 :format content-type)))))
@@ -1381,13 +1405,13 @@ ones, in case fg and bg are nil."
1381(defun shr-tag-sup (dom) 1405(defun shr-tag-sup (dom)
1382 (let ((start (point))) 1406 (let ((start (point)))
1383 (shr-generic dom) 1407 (shr-generic dom)
1384 (put-text-property start (point) 'display '(raise 0.2)) 1408 (put-text-property start (point) 'display `(raise ,shr-sup-raise-factor))
1385 (add-face-text-property start (point) 'shr-sup))) 1409 (add-face-text-property start (point) 'shr-sup)))
1386 1410
1387(defun shr-tag-sub (dom) 1411(defun shr-tag-sub (dom)
1388 (let ((start (point))) 1412 (let ((start (point)))
1389 (shr-generic dom) 1413 (shr-generic dom)
1390 (put-text-property start (point) 'display '(raise -0.2)) 1414 (put-text-property start (point) 'display `(raise ,shr-sub-raise-factor))
1391 (add-face-text-property start (point) 'shr-sup))) 1415 (add-face-text-property start (point) 'shr-sup)))
1392 1416
1393(defun shr-tag-p (dom) 1417(defun shr-tag-p (dom)
@@ -1840,7 +1864,7 @@ BASE is the URL of the HTML being rendered."
1840 (svg-rectangle svg 0 0 width height :gradient "background" 1864 (svg-rectangle svg 0 0 width height :gradient "background"
1841 :stroke-width 2 :stroke-color "black") 1865 :stroke-width 2 :stroke-color "black")
1842 (let ((image (svg-image svg :scale 1))) 1866 (let ((image (svg-image svg :scale 1)))
1843 (setf (image-property image :ascent) 100) 1867 (setf (image-property image :ascent) shr-image-ascent)
1844 image))) 1868 image)))
1845 1869
1846(defun shr-tag-pre (dom) 1870(defun shr-tag-pre (dom)