[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/htmlize 5dbea0b 079/134: Convert the auto-link-creation ma
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/htmlize 5dbea0b 079/134: Convert the auto-link-creation machinery to use the `htmlize-link' property. |
Date: |
Sat, 7 Aug 2021 09:17:11 -0400 (EDT) |
branch: elpa/htmlize
commit 5dbea0b16a91e3bd88925acfdea6c66073ac1f86
Author: Hrvoje Niksic <hniksic@gmail.com>
Commit: Hrvoje Niksic <hniksic@gmail.com>
Convert the auto-link-creation machinery to use the `htmlize-link' property.
This is done by creating temporary overlays.
---
htmlize.el | 74 +++++++++++++++++++++++++++++++++-----------------------------
1 file changed, 40 insertions(+), 34 deletions(-)
diff --git a/htmlize.el b/htmlize.el
index 73c5940..81c12a4 100644
--- a/htmlize.el
+++ b/htmlize.el
@@ -166,10 +166,12 @@ Returning nil is the same as returning the original text."
:group 'htmlize)
(defcustom htmlize-generate-hyperlinks t
- "Non-nil means generate the hyperlinks for URLs and mail addresses.
+ "Non-nil means auto-generate the links from URLs and mail addresses in
buffer.
+
This is on by default; set it to nil if you don't want htmlize to
-insert hyperlinks in the resulting HTML. (In which case you can still
-do your own hyperlinkification from htmlize-after-hook.)"
+autogenerate such links. Note that this option only turns off automatic
+search for contents that looks like URLs and converting them to links.
+It has no effect on whether htmlize respects the `htmlize-link' property."
:type 'boolean
:group 'htmlize)
@@ -763,39 +765,42 @@ list."
(values text trailing-ellipsis)))
(defun htmlize-despam-address (string)
- "Replace every occurrence of '@' in STRING with @.
-`htmlize-make-hyperlinks' uses this to spam-protect mailto links
-without modifying their meaning."
+ "Replace every occurrence of '@' in STRING with %40.
+This is used to protect mailto links without modifying their meaning."
;; Suggested by Ville Skytta.
(while (string-match "@" string)
- (setq string (replace-match "@" nil t string)))
+ (setq string (replace-match "%40" nil t string)))
string)
-(defun htmlize-make-hyperlinks ()
- "Make hyperlinks in HTML."
+(defun htmlize-make-link-overlay (beg end uri)
+ (let ((overlay (make-overlay beg end)))
+ (overlay-put overlay 'htmlize-link (list :uri uri))
+ overlay))
+
+(defun htmlize-create-auto-links ()
+ "Add `htmlize-link' property to all mailto links in the buffer.
+Returns the list of created overlays."
;; Function originally submitted by Ville Skytta. Rewritten by
;; Hrvoje Niksic, then modified by Ville Skytta and Hrvoje Niksic.
- (goto-char (point-min))
- (while (re-search-forward
- "<\\(\\(mailto:\\)?\\([-=+_.a-zA-Z0-9]+@[-_.a-zA-Z0-9]+\\)\\)>"
- nil t)
- (let ((address (match-string 3))
- (link-text (match-string 1)))
- (delete-region (match-beginning 0) (match-end 0))
- (insert "<<a href=\"mailto:"
- (htmlize-despam-address address)
- "\">"
- (htmlize-despam-address link-text)
- "</a>>")))
- (goto-char (point-min))
- (while (re-search-forward "<\\(\\(URL:\\)?\\([a-zA-Z]+://[^;]+\\)\\)>"
- nil t)
- (let ((url (match-string 3))
- (link-text (match-string 1)))
- (delete-region (match-beginning 0) (match-end 0))
- (insert "<<a href=\"" url "\">" link-text "</a>>"))))
-
-;; Tests for htmlize-make-hyperlinks:
+ (let ((overlays nil))
+ (save-excursion
+ (goto-char (point-min))
+ (while (re-search-forward
+ "<\\(\\(mailto:\\)?\\([-=+_.a-zA-Z0-9]+@[-_.a-zA-Z0-9]+\\)\\)>"
+ nil t)
+ (let* ((address (match-string 3))
+ (beg (match-beginning 0)) (end (match-end 0))
+ (uri (concat "mailto:" (htmlize-despam-address address))))
+ (push (htmlize-make-link-overlay beg end uri) overlays)))
+ (goto-char (point-min))
+ (while (re-search-forward "<\\(\\(URL:\\)?\\([a-zA-Z]+://[^;]+\\)\\)>"
+ nil t)
+ (push (htmlize-make-link-overlay
+ (match-beginning 0) (match-end 0) (match-string 3))
+ overlays)))
+ overlays))
+
+;; Tests for htmlize-create-auto-links:
;; <mailto:hniksic@xemacs.org>
;; <http://fly.srk.fer.hr>
@@ -1570,7 +1575,9 @@ it's called with the same value of KEY. All other times,
the cached
(file-name-nondirectory
(buffer-file-name)))
"*html*")))
- (completed nil))
+ (completed nil)
+ (auto-link-overlays (and htmlize-generate-hyperlinks
+ (htmlize-create-auto-links))))
(unwind-protect
(let* ((buffer-faces (htmlize-faces-in-buffer))
(face-map (htmlize-make-face-map (adjoin 'default
buffer-faces)))
@@ -1654,8 +1661,6 @@ it's called with the same value of KEY. All other times,
the cached
(insert "\n </body>")
(put places 'body-end (point-marker))
(insert "\n</html>\n")
- (when htmlize-generate-hyperlinks
- (htmlize-make-hyperlinks))
(htmlize-defang-local-variables)
(when htmlize-replace-form-feeds
;; Change each "\n^L" to "<hr />".
@@ -1682,7 +1687,8 @@ it's called with the same value of KEY. All other times,
the cached
htmlbuf)
(when (not completed)
- (kill-buffer htmlbuf))))))
+ (kill-buffer htmlbuf))
+ (mapc #'delete-overlay auto-link-overlays)))))
;; Utility functions.
- [nongnu] elpa/htmlize 9349d4b 014/134: Version 1.4., (continued)
- [nongnu] elpa/htmlize 9349d4b 014/134: Version 1.4., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 2e7cb2c 021/134: Version 1.37., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 1a14031 022/134: New file: .gitignore, ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 665abf9 024/134: Use `put' instead of `plist-put'., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 814e537 026/134: Update instructions for git., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize bcf1d44 025/134: Update copyright and compress individual years to ranges., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 3477a7d 027/134: Bump version., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 61760b4 075/134: Implement the `htmlize-link' property to embed links in the HTML., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 296b18e 033/134: Extract a bit of code outside buffer-substring-no-invisible., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize e3d020e 059/134: Remove explicit references to MULE., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 5dbea0b 079/134: Convert the auto-link-creation machinery to use the `htmlize-link' property.,
ELPA Syncer <=
- [nongnu] elpa/htmlize bad6391 082/134: Look for PROP., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 380ba4b 084/134: Bumped version., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 5b29cde 090/134: Update NEWS., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 7eb326a 099/134: Fix package header format, ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 4570d0a 103/134: Add README., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 8f46e10 105/134: Use htmlpreview., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 78318a2 114/134: Support face-remapping-alist. (#13), ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 9b49540 133/134: Replace cl with cl-lib, ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize a040bdd 127/134: Don't try to call color-instance-rgb-components., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 0a73b2b 043/134: Change `insert-text' method to `text-markup', so that the text can be, ELPA Syncer, 2021/08/07