[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/htmlize 11fec7b 050/134: Recognize the `display' property
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/htmlize 11fec7b 050/134: Recognize the `display' property and render it into the HTML, including images. |
Date: |
Sat, 7 Aug 2021 09:17:04 -0400 (EDT) |
branch: elpa/htmlize
commit 11fec7b59ce06f34d98975470b60826a924c1835
Author: Hrvoje Niksic <hniksic@gmail.com>
Commit: Hrvoje Niksic <hniksic@gmail.com>
Recognize the `display' property and render it into the HTML, including
images.
---
htmlize.el | 39 +++++++++++++++++++++++++++++++++++++--
1 file changed, 37 insertions(+), 2 deletions(-)
diff --git a/htmlize.el b/htmlize.el
index 8845ad8..6c38382 100644
--- a/htmlize.el
+++ b/htmlize.el
@@ -407,6 +407,27 @@ next-single-char-property-change")))
(char-to-string char)))))
string "")))
+(defun htmlize-string-to-html (string)
+ (let ((pos 0) (end (length string))
+ display output next-change)
+ (while (< pos end)
+ (setq display (get-char-property pos 'display string)
+ next-change (next-single-property-change pos 'display string end))
+ (cond ((stringp display)
+ (push (htmlize-protect-string display) output))
+ ((eq (car-safe display) 'image)
+ (push (htmlize-generate-image (cdr display)) output))
+ (t
+ (push (htmlize-protect-string (substring string pos next-change))
+ output)))
+ (setq pos next-change))
+ (apply #'concat (nreverse output))))
+
+(defun htmlize-generate-image (imgprops)
+ (cond ((plist-get imgprops :file)
+ (format "<img src=\"%s\" />"
+ (htmlize-protect-string (plist-get imgprops :file))))))
+
(defconst htmlize-ellipsis "...")
(put-text-property 0 (length htmlize-ellipsis) 'htmlize-ellipsis t
htmlize-ellipsis)
@@ -438,6 +459,19 @@ next-single-char-property-change")))
((cdr-safe (car match)) 'ellipsis)
(t nil)))))
+(defun htmlize-get-text-with-display (beg end)
+ (let ((pos beg)
+ (text (buffer-substring-no-properties beg end))
+ display next-change)
+ (while (< pos end)
+ (setq display (get-char-property pos 'display)
+ next-change (htmlize-next-change pos 'display end))
+ (when display
+ (put-text-property (- pos beg) (- next-change beg)
+ 'display display text))
+ (setq pos next-change))
+ text))
+
(defun htmlize-buffer-substring-no-invisible (beg end)
;; Like buffer-substring-no-properties, but don't copy invisible
;; parts of the region. Where buffer-substring-no-properties
@@ -452,7 +486,8 @@ next-single-char-property-change")))
next-change (htmlize-next-change pos 'invisible end)
show (htmlize-decode-invisibility-spec invisible))
(cond ((eq show t)
- (push (buffer-substring-no-properties pos next-change)
visible-list))
+ (push (htmlize-get-text-with-display pos next-change)
+ visible-list))
((and (eq show 'ellipsis)
(not (eq last-show 'ellipsis))
;; Conflate successive ellipses.
@@ -529,7 +564,7 @@ next-single-char-property-change")))
(get-text-property (1- (length text))
'htmlize-ellipsis text)))
(setq text (htmlize-untabify text (current-column)))
- (setq text (htmlize-protect-string text))
+ (setq text (htmlize-string-to-html text))
(values text trailing-ellipsis)))
(defun htmlize-despam-address (string)
- [nongnu] elpa/htmlize 179f267 036/134: Bump version., (continued)
- [nongnu] elpa/htmlize 179f267 036/134: Bump version., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 06e9a88 037/134: Make the header package.el compatible, ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize aa7969b 038/134: Bump version., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize c0bea5b 040/134: Don't use the old name x-color-values., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 11e675b 041/134: Get rid of a silly warning., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 3dfd7c9 044/134: Insert multiple runs having the same fstruct-list with the same HTML markup., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize cbbbc47 045/134: Kill htmlbuf in case of error., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 98c2c97 046/134: Update the copyright year., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize b95dd46 047/134: Fix docstring and indent., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 143baca 048/134: Fix the `font' method., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 11fec7b 050/134: Recognize the `display' property and render it into the HTML, including images.,
ELPA Syncer <=
- [nongnu] elpa/htmlize f7cc2af 051/134: Display a buffer portion with a single `display' property as a single, ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize c34b364 053/134: Create an image with a data: URI for image data descriptors., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize c13175c 058/134: Don't use CL's lexical-let if lexical binding is in use., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 97b6b8d 078/134: Escape link text., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 5ce4c6e 083/134: Support XEmacs again., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize aa6e2f6 096/134: Removed support for GNU Emacs 21., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 29f3960 104/134: Nicer readme., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize fb85e84 005/134: Version 0.45., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 94faffa 056/134: Just use `locate-file'., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 3551c6b 063/134: Respect `before-string' and `after-string' overlay properties., ELPA Syncer, 2021/08/07