>From a46810e54ba2590cae88cde09445bfc34a5ac77b Mon Sep 17 00:00:00 2001 From: Rahguzar Date: Mon, 23 Oct 2023 21:23:53 +0200 Subject: [PATCH 1/5] Make some aspects of shr rendering customizable * lisp/net/shr.el (shr-fill-text): New custom variable (shr-sup-raise-factor): New custom variable (shr-sub-raise-factor): New custom variable (shr-image-ascent): New custom variable (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): Use shr-image-ascent (shr-make-placeholder-image): Use shr-image-ascent (shr-tag-sup): use shr-sup-raise-factor (shr-tag-sub): use shr-sub-raise-factor --- lisp/net/shr.el | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/lisp/net/shr.el b/lisp/net/shr.el index 645e1cc51e5..185f2c0422d 100644 --- a/lisp/net/shr.el +++ b/lisp/net/shr.el @@ -163,6 +163,30 @@ shr-offer-extend-specpdl :version "28.1" :type 'boolean) +(defcustom shr-fill-text t + "Non-nil means to fill the text according to the width of the window. +If nil text is not filled and `visual-line-mode' can be used to reflow text." + :version "30.1" + :type 'boolean) + + +(defcustom shr-sup-raise-factor 0.2 + "The value of raise property for superscripts. +Should be a number between 0 and 1." + :version "30.1" + :type 'float) + +(defcustom shr-sub-raise-factor -0.2 + "The value of raise property for subscripts. +Should be a number between 0 and -1." + :version "30.1" + :type 'float) + +(defcustom shr-image-ascent 100 + "The value to be used for :ascent property when inserting images." + :version "30.1" + :type 'integer) + (defvar shr-content-function nil "If bound, this should be a function that will return the content. This is used for cid: URLs, and the function is called with the @@ -741,7 +765,7 @@ shr-insert (or shr-current-font 'shr-text))))))))) (defun shr-fill-lines (start end) - (if (<= shr-internal-width 0) + (if (or (not shr-fill-text) (<= shr-internal-width 0)) nil (save-restriction (narrow-to-region start end) @@ -1063,11 +1087,11 @@ shr-put-image (start (point)) (image (cond ((eq size 'original) - (create-image data nil t :ascent 100 + (create-image data nil t :ascent shr-image-ascent :format content-type)) ((eq content-type 'image/svg+xml) (when (image-type-available-p 'svg) - (create-image data 'svg t :ascent 100))) + (create-image data 'svg t :ascent shr-image-ascent))) ((eq size 'full) (ignore-errors (shr-rescale-image data content-type @@ -1114,7 +1138,7 @@ shr-rescale-image MAX-WIDTH/MAX-HEIGHT. If not given, use the current window width/height instead." (if (not (get-buffer-window (current-buffer) t)) - (create-image data nil t :ascent 100) + (create-image data nil t :ascent shr-image-ascent) (let* ((edges (window-inside-pixel-edges (get-buffer-window (current-buffer)))) (max-width (truncate (* shr-max-image-proportion @@ -1135,13 +1159,13 @@ shr-rescale-image (< (* height scaling) max-height)) (create-image data (shr--image-type) t - :ascent 100 + :ascent shr-image-ascent :width width :height height :format content-type) (create-image data (shr--image-type) t - :ascent 100 + :ascent shr-image-ascent :max-width max-width :max-height max-height :format content-type))))) @@ -1381,13 +1405,13 @@ shr-tag-svg (defun shr-tag-sup (dom) (let ((start (point))) (shr-generic dom) - (put-text-property start (point) 'display '(raise 0.2)) + (put-text-property start (point) 'display `(raise ,shr-sup-raise-factor)) (add-face-text-property start (point) 'shr-sup))) (defun shr-tag-sub (dom) (let ((start (point))) (shr-generic dom) - (put-text-property start (point) 'display '(raise -0.2)) + (put-text-property start (point) 'display `(raise ,shr-sub-raise-factor)) (add-face-text-property start (point) 'shr-sup))) (defun shr-tag-p (dom) @@ -1840,7 +1864,7 @@ shr-make-placeholder-image (svg-rectangle svg 0 0 width height :gradient "background" :stroke-width 2 :stroke-color "black") (let ((image (svg-image svg :scale 1))) - (setf (image-property image :ascent) 100) + (setf (image-property image :ascent) shr-image-ascent) image))) (defun shr-tag-pre (dom) -- 2.42.0