[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/htmlize 7947b8b 074/134: Don't generate ALT text larger th
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/htmlize 7947b8b 074/134: Don't generate ALT text larger than 100 chars or containing control chars. |
Date: |
Sat, 7 Aug 2021 09:17:10 -0400 (EDT) |
branch: elpa/htmlize
commit 7947b8b33aeadb74d36b8e2cae70f540582f3745
Author: Hrvoje Niksic <hniksic@gmail.com>
Commit: Hrvoje Niksic <hniksic@gmail.com>
Don't generate ALT text larger than 100 chars or containing control chars.
---
htmlize.el | 25 ++++++++++++++++++++-----
1 file changed, 20 insertions(+), 5 deletions(-)
diff --git a/htmlize.el b/htmlize.el
index 4f7948a..9399e22 100644
--- a/htmlize.el
+++ b/htmlize.el
@@ -145,6 +145,14 @@ embedded in the HTML as data URIs."
:type 'boolean
:group 'htmlize)
+(defcustom htmlize-max-alt-text 100
+ "*Maximum size of text to use as ALT text in images.
+
+Normally when htmlize encounters text covered by the `display' property
+that specifies an image, it generates an `alt' attribute containing the
+original text. If the text is larger than `htmlize-max-alt-text' characters,
+this will not be done.")
+
(defcustom htmlize-transform-image 'htmlize-default-transform-image
"*Function called to modify the image descriptor.
@@ -524,10 +532,17 @@ list."
:data data)))
imgprops)))
+(defun htmlize-alt-text (_imgprops origtext)
+ (and (/= (length origtext) 0)
+ (<= (length origtext) htmlize-max-alt-text)
+ (not (string-match "[\0-\x1f]" origtext))
+ origtext))
+
(defun htmlize-generate-image (imgprops origtext)
- (let ((alt (if (zerop (length origtext))
- ""
- (format " alt=\"%s\"" (htmlize-attr-escape origtext)))))
+ (let* ((alt-text (htmlize-alt-text imgprops origtext))
+ (alt-attr (if alt-text
+ (format " alt=\"%s\"" (htmlize-attr-escape alt-text))
+ "")))
(cond ((plist-get imgprops :file)
;; Try to find the image in image-load-path
(let* ((found-props (cdr (find-image (list imgprops))))
@@ -535,12 +550,12 @@ list."
(plist-get imgprops :file))))
(format "<img src=\"%s\"%s />"
(htmlize-attr-escape (file-relative-name file))
- alt)))
+ alt-attr)))
((plist-get imgprops :data)
(format "<img src=\"data:image/%s;base64,%s\"%s />"
(or (plist-get imgprops :type) "")
(base64-encode-string (plist-get imgprops :data))
- alt)))))
+ alt-attr)))))
(defconst htmlize-ellipsis "...")
(put-text-property 0 (length htmlize-ellipsis) 'htmlize-ellipsis t
htmlize-ellipsis)
- [nongnu] elpa/htmlize 3308bf9 052/134: Preserve the `display' property during untabification., (continued)
- [nongnu] elpa/htmlize 3308bf9 052/134: Preserve the `display' property during untabification., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 62020d5 054/134: Fix erroneous comment., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize ef8b865 055/134: Add some docs., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 148ac7d 061/134: Consistently eliminate unnecessary string creation in (apply #'concat ...)., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 3faeac8 069/134: Explicitly mark sort as stable., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize af69752 062/134: Consistently handle the multitude of ways to specify the `face' property., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 0ba773b 067/134: Specify some `rgb.txt' locations that actually exist!, ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 6baf891 070/134: Implement customizable image transformation, htmlize-force-inline-images, and image alt text., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize ba5ddf3 073/134: Enable edebug stepping into htmlize-lexlet., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 6b3b3b6 077/134: Purge asterisks from variable docstrings., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 7947b8b 074/134: Don't generate ALT text larger than 100 chars or containing control chars.,
ELPA Syncer <=
- [nongnu] elpa/htmlize 93294ff 091/134: Bumped version., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize a4569e3 092/134: Correctly handle :inherit specifying a list of faces., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 31bc1a8 094/134: Remove stray debugging print., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 8c09264 097/134: Bump version and copyright., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize a95e591 107/134: Bump version., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 2c41d79 101/134: Update mail address., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 9d4ad62 102/134: Set type and group attribute for custom variable, ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 88e2cb6 109/134: Update copyright info., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 5ea2cc3 113/134: Let `overlays-at' sort the overlays. (#9), ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 1bc2f1b 118/134: Bump version., ELPA Syncer, 2021/08/07