diff lisp/gnus/html2text.el @ 57856:df80d19d7a2e

Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-660 Merge from gnus--rel--5.10 Patches applied: * miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-65 Update from CVS 2004-11-01 Reiner Steib <Reiner.Steib@gmx.de> * lisp/gnus/gnus-msg.el (gnus-summary-resend-default-address): Add :version. * lisp/gnus/tls.el (tls-process-connection-type, tls-success) (tls-certtool-program): Add :version. * lisp/gnus/starttls.el (starttls-gnutls-program, starttls-use-gnutls) (starttls-extra-arguments, starttls-process-connection-type) (starttls-connect, starttls-failure, starttls-success): * lisp/gnus/spam-stat.el (spam-stat): Add :version. * lisp/gnus/sieve.el (sieve): Add :version. * lisp/gnus/sha1.el (sha1): Added :version. (sha1-use-external): Removed redundant version. * lisp/gnus/nnmail.el (nnmail-split-fancy-with-parent-ignore-groups) (nnmail-cache-ignore-groups, nnmail-spool-hook) (nnmail-split-fancy-match-partial-words) (nnmail-split-lowercase-expanded): * lisp/gnus/nndiary.el (nndiary): Add :version. * lisp/gnus/mml2015.el (mml2015-unabbrev-trust-alist): Add :version. * lisp/gnus/mml-sec.el (mml-default-sign-method) (mml-default-encrypt-method, mml-signencrypt-style-alist): Add :version. * lisp/gnus/mm-uu.el (mm-uu-diff-groups-regexp): Add :version. * lisp/gnus/mm-url.el (mm-url-use-external, mm-url-program) (mm-url-arguments): Add :version. * lisp/gnus/mm-decode.el (mm-inline-text-html-with-w3m-keymap) (mm-attachment-file-modes, mm-decrypt-option) (mm-w3m-safe-url-regexp): Add :version. * lisp/gnus/message.el (message-cite-prefix-regexp) (message-sendmail-envelope-from, message-minibuffer-local-map) (message-user-fqdn, message-completion-alist): Add :version. * lisp/gnus/gnus-win.el (gnus-configure-windows-hook) (gnus-use-frames-on-any-display): Add :version. * lisp/gnus/gnus-art.el (gnus-article-address-banner-alist) (gnus-treat-unsplit-urls, gnus-treat-unfold-headers) (gnus-treat-from-picon, gnus-treat-mail-picon) (gnus-treat-x-pgp-sig): Add :version. * lisp/gnus/gnus-sum.el (gnus-spam-mark, gnus-recent-mark) (gnus-undownloaded-mark, gnus-summary-article-move-hook) (gnus-summary-article-delete-hook) (gnus-summary-display-while-building): Add :version. * lisp/gnus/gnus-start.el (gnus-subscribe-newsgroup-hooks) (gnus-get-top-new-news-hook):Add :version. * lisp/gnus/gnus-srvr.el (gnus-server-agent-face, gnus-server-opened-face) (gnus-server-closed-face, gnus-server-denied-face): Add :version. * lisp/gnus/gnus-registry.el (gnus-registry): Add :version. * lisp/gnus/gnus-spec.el (gnus-use-correct-string-widths) (gnus-make-format-preserve-properties): Add :version. * lisp/gnus/gnus.el (gnus-group-charter-alist) (gnus-group-fetch-control-use-browse-url) (gnus-install-group-spam-parameters): Add :version. * lisp/gnus/gnus-diary.el (gnus-diary): Add :version. * lisp/gnus/gnus-delay.el (gnus-delay): Add :version. * lisp/gnus/gnus-cite.el (gnus-cite-unsightly-citation-regexp) (gnus-cite-ignore-quoted-from, gnus-cite-attribution-face) (gnus-cite-blank-line-after-header, gnus-article-boring-faces): Add :version. * lisp/gnus/gnus-agent.el (gnus-agent-max-fetch-size) (gnus-agent-enable-expiration, gnus-agent-queue-mail) (gnus-agent-prompt-send-queue): Add :version. * lisp/gnus/deuglify.el (gnus-outlook-deuglify): Add :version. * lisp/gnus/html2text.el: Beautify code. Improve doc strings. Some checkdoc cleanup. (html2text-get-attr, html2text-fix-paragraph): Simplify code. (html2text-format-tag-list): Added "strong" and "em". From "Alfred M. Szmidt" <ams@kemisten.nu> (tiny change).
author Miles Bader <miles@gnu.org>
date Mon, 01 Nov 2004 23:06:36 +0000
parents 6a65cb24e1be
children d7def5572cf3
line wrap: on
line diff
--- a/lisp/gnus/html2text.el	Mon Nov 01 23:06:32 2004 +0000
+++ b/lisp/gnus/html2text.el	Mon Nov 01 23:06:36 2004 +0000
@@ -24,11 +24,11 @@
 
 ;; These functions provide a simple way to wash/clean html infected
 ;; mails.  Definitely do not work in all cases, but some improvement
-;; in readability is generally obtained. Formatting is only done in
+;; in readability is generally obtained.  Formatting is only done in
 ;; the buffer, so the next time you enter the article it will be
 ;; "re-htmlized".
 ;;
-;; The main function is "html2text"
+;; The main function is `html2text'.
 
 ;;; Code:
 
@@ -47,9 +47,9 @@
   "The map of entity to text.
 
 This is an alist were each element is a dotted pair consisting of an
-old string, and a replacement string. This replacement is done by the
-function \"html2text-substitute\" which basically performs a
-replace-string operation for every element in the list. This is
+old string, and a replacement string.  This replacement is done by the
+function `html2text-substitute' which basically performs a
+`replace-string' operation for every element in the list.  This is
 completely verbatim - without any use of REGEXP.")
 
 (defvar html2text-remove-tag-list
@@ -57,11 +57,11 @@
   "A list of removable tags.
 
 This is a list of tags which should be removed, without any
-formatting.  Observe that if you the tags in the list are presented
-*without* any \"<\" or \">\". All occurences of a tag appearing in
-this list are removed, irrespective of whether it is a closing or
-opening tag, or if the tag has additional attributes. The actual
-deletion is done by the function \"html2text-remove-tags\".
+formatting.  Note that tags in the list are presented *without*
+any \"<\" or \">\".  All occurences of a tag appearing in this
+list are removed, irrespective of whether it is a closing or
+opening tag, or if the tag has additional attributes.  The
+deletion is done by the function `html2text-remove-tags'.
 
 For instance the text:
 
@@ -75,8 +75,10 @@
 
 (defvar html2text-format-tag-list
   '(("b" 	  . html2text-clean-bold)
+    ("strong"     . html2text-clean-bold)
     ("u" 	  . html2text-clean-underline)
     ("i" 	  . html2text-clean-italic)
+    ("em"         . html2text-clean-italic)
     ("blockquote" . html2text-clean-blockquote)
     ("a"          . html2text-clean-anchor)
     ("ul"         . html2text-clean-ul)
@@ -86,7 +88,7 @@
   "An alist of tags and processing functions.
 
 This is an alist where each dotted pair consists of a tag, and then
-the name of a function to be called when this tag is found. The
+the name of a function to be called when this tag is found.  The
 function is called with the arguments p1, p2, p3 and p4. These are
 demontrated below:
 
@@ -117,17 +119,15 @@
 ;;
 
 
-(defun html2text-replace-string (from-string to-string p1 p2)
-  (goto-char p1)
+(defun html2text-replace-string (from-string to-string min max)
+  "Replace FROM-STRING with TO-STRING in region from MIN to MAX."
+  (goto-char min)
   (let ((delta (- (string-width to-string) (string-width from-string)))
 	(change 0))
-    (while (search-forward from-string p2 t)
+    (while (search-forward from-string max t)
       (replace-match to-string)
-      (setq change (+ change delta))
-      )
-    change
-    )
-  )
+      (setq change (+ change delta)))
+    change))
 
 ;;
 ;; </Utility functions>
@@ -140,9 +140,9 @@
 ;; <Functions related to attributes> i.e. <font size=+3>
 ;;
 
-(defun html2text-attr-value (attr-list attr)
-  (nth 1 (assoc attr attr-list))
-  )
+(defun html2text-attr-value (list attribute)
+  "Get value of ATTRIBUTE from LIST."
+  (nth 1 (assoc attribute list)))
 
 (defun html2text-get-attr (p1 p2 tag)
   (goto-char p1)
@@ -161,14 +161,10 @@
      ((string-match "[^ ]=[^ ]" prev)
       (let ((attr  (nth 0 (split-string prev "=")))
 	    (value (nth 1 (split-string prev "="))))
-	(setq attr-list (cons (list attr value) attr-list))
-	)
-      )
+	(setq attr-list (cons (list attr value) attr-list))))
      ;; size= 3
      ((string-match "[^ ]=\\'" prev)
-      (setq attr-list (cons (list (substring prev 0 -1) this) attr-list))
-      )
-     )
+      (setq attr-list (cons (list (substring prev 0 -1) this) attr-list))))
 
     (while (< index (length tmp-list))
       (cond
@@ -176,29 +172,20 @@
        ((string-match "[^ ]=[^ ]" this)
 	(let ((attr  (nth 0 (split-string this "=")))
 	      (value (nth 1 (split-string this "="))))
-	  (setq attr-list (cons (list attr value) attr-list))
-	  )
-	)
+	  (setq attr-list (cons (list attr value) attr-list))))
        ;; size =3
        ((string-match "\\`=[^ ]" this)
 	(setq attr-list (cons (list prev (substring this 1)) attr-list)))
-
        ;; size= 3
        ((string-match "[^ ]=\\'" this)
-	(setq attr-list (cons (list (substring this 0 -1) next) attr-list))
-	)
-
+	(setq attr-list (cons (list (substring this 0 -1) next) attr-list)))
        ;; size = 3
        ((string= "=" this)
-	(setq attr-list (cons (list prev next) attr-list))
-	)
-       )
+	(setq attr-list (cons (list prev next) attr-list))))
       (setq index (1+ index))
       (setq prev this)
       (setq this next)
-      (setq next (nth (1+ index) tmp-list))
-      )
-
+      (setq next (nth (1+ index) tmp-list)))
     ;;
     ;; Tags with no accompanying "=" i.e. value=nil
     ;;
@@ -207,41 +194,25 @@
     (setq next (nth 2 tmp-list))
     (setq index 1)
 
-    (if (not (string-match "=" prev))
-	(progn
-	  (if (not (string= (substring this 0 1) "="))
-	      (setq attr-list (cons (list prev nil) attr-list))
-	    )
-	  )
-      )
-
+    (when (and (not (string-match "=" prev))
+	       (not (string= (substring this 0 1) "=")))
+      (setq attr-list (cons (list prev nil) attr-list)))
     (while (< index (1- (length tmp-list)))
-      (if (not (string-match "=" this))
-	  (if (not (or (string= (substring next 0 1) "=")
-		       (string= (substring prev -1) "=")))
-	      (setq attr-list (cons (list this nil) attr-list))
-	    )
-	)
+      (when (and (not (string-match "=" this))
+		 (not (or (string= (substring next 0 1) "=")
+			  (string= (substring prev -1) "="))))
+	(setq attr-list (cons (list this nil) attr-list)))
       (setq index (1+ index))
       (setq prev this)
       (setq this next)
-      (setq next (nth (1+ index) tmp-list))
-      )
+      (setq next (nth (1+ index) tmp-list)))
 
-    (if this
-	(progn
-	  (if (not (string-match "=" this))
-	      (progn
-		(if (not (string= (substring prev -1) "="))
-		    (setq attr-list (cons (list this nil) attr-list))
-		  )
-		)
-	    )
-	  )
-      )
-    attr-list ;; return - value
-    )
-  )
+    (when (and this
+	       (not (string-match "=" this))
+	       (not (string= (substring prev -1) "=")))
+      (setq attr-list (cons (list this nil) attr-list)))
+    ;; return - value
+    attr-list))
 
 ;;
 ;; </Functions related to attributes>
@@ -266,10 +237,7 @@
       (cond
        ((string= list-type "ul") (insert " o "))
        ((string= list-type "ol") (insert (format " %s: " item-nr)))
-       (t (insert " x ")))
-      )
-    )
-  )
+       (t (insert " x "))))))
 
 (defun html2text-clean-dtdd (p1 p2)
   (goto-char p1)
@@ -308,60 +276,50 @@
   (html2text-delete-single-tag p1 p2)
   (goto-char p1)
   (newline 1)
-  (insert (make-string fill-column ?-))
-  )
+  (insert (make-string fill-column ?-)))
 
 (defun html2text-clean-ul (p1 p2 p3 p4)
   (html2text-delete-tags p1 p2 p3 p4)
-  (html2text-clean-list-items p1 (- p3 (- p1 p2)) "ul")
-  )
+  (html2text-clean-list-items p1 (- p3 (- p1 p2)) "ul"))
 
 (defun html2text-clean-ol (p1 p2 p3 p4)
   (html2text-delete-tags p1 p2 p3 p4)
-  (html2text-clean-list-items p1 (- p3 (- p1 p2)) "ol")
-  )
+  (html2text-clean-list-items p1 (- p3 (- p1 p2)) "ol"))
 
 (defun html2text-clean-dl (p1 p2 p3 p4)
   (html2text-delete-tags p1 p2 p3 p4)
-  (html2text-clean-dtdd p1 (- p3 (- p1 p2)))
-  )
+  (html2text-clean-dtdd p1 (- p3 (- p1 p2))))
 
 (defun html2text-clean-center (p1 p2 p3 p4)
   (html2text-delete-tags p1 p2 p3 p4)
-  (center-region p1 (- p3 (- p2 p1)))
-  )
+  (center-region p1 (- p3 (- p2 p1))))
 
 (defun html2text-clean-bold (p1 p2 p3 p4)
   (put-text-property p2 p3 'face 'bold)
-  (html2text-delete-tags p1 p2 p3 p4)
-  )
+  (html2text-delete-tags p1 p2 p3 p4))
 
 (defun html2text-clean-title (p1 p2 p3 p4)
   (put-text-property p2 p3 'face 'bold)
-  (html2text-delete-tags p1 p2 p3 p4)
-  )
+  (html2text-delete-tags p1 p2 p3 p4))
 
 (defun html2text-clean-underline (p1 p2 p3 p4)
   (put-text-property p2 p3 'face 'underline)
-  (html2text-delete-tags p1 p2 p3 p4)
-  )
+  (html2text-delete-tags p1 p2 p3 p4))
 
 (defun html2text-clean-italic (p1 p2 p3 p4)
   (put-text-property p2 p3 'face 'italic)
-  (html2text-delete-tags p1 p2 p3 p4)
-  )
+  (html2text-delete-tags p1 p2 p3 p4))
 
 (defun html2text-clean-font (p1 p2 p3 p4)
-  (html2text-delete-tags p1 p2 p3 p4)
-  )
+  (html2text-delete-tags p1 p2 p3 p4))
 
 (defun html2text-clean-blockquote (p1 p2 p3 p4)
-  (html2text-delete-tags p1 p2 p3 p4)
-  )
+  (html2text-delete-tags p1 p2 p3 p4))
 
 (defun html2text-clean-anchor (p1 p2 p3 p4)
-  ;; If someone can explain how to make the URL clickable I will
-  ;; surely improve upon this.
+  ;; If someone can explain how to make the URL clickable I will surely
+  ;; improve upon this.
+  ;; Maybe `goto-addr.el' can be used here.
   (let* ((attr-list (html2text-get-attr p1 p2 "a"))
 	 (href (html2text-attr-value attr-list "href")))
     (delete-region p1 p4)
@@ -386,38 +344,27 @@
   (let ((has-br-line)
 	(refill-start)
 	(refill-stop))
-    (if (re-search-forward "<br>$" p2 t)
-	(setq has-br-line t)
-      )
-    (if has-br-line
-	(progn
-	  (goto-char p1)
-	  (if (re-search-forward ".+[^<][^b][^r][^>]$" p2 t)
-	      (progn
-		(beginning-of-line)
-		(setq refill-start (point))
-		(goto-char p2)
-		(re-search-backward ".+[^<][^b][^r][^>]$" refill-start t)
-		(next-line 1)
-		(end-of-line)
-		;; refill-stop should ideally be adjusted to
-		;; accomodate the "<br>" strings which are removed
-		;; between refill-start and refill-stop.  Can simply
-		;; be returned from my-replace-string
-		(setq refill-stop (+ (point)
-				     (html2text-replace-string
-				      "<br>" ""
-				      refill-start (point))))
-		;; (message "Point = %s  refill-stop = %s" (point) refill-stop)
-		;; (sleep-for 4)
-		(fill-region refill-start refill-stop)
-		)
-	    )
-	  )
-      )
-    )
-  (html2text-replace-string "<br>" "" p1 p2)
-  )
+    (when (re-search-forward "<br>$" p2 t)
+      (goto-char p1)
+      (when (re-search-forward ".+[^<][^b][^r][^>]$" p2 t)
+	(beginning-of-line)
+	(setq refill-start (point))
+	(goto-char p2)
+	(re-search-backward ".+[^<][^b][^r][^>]$" refill-start t)
+	(next-line 1)
+	(end-of-line)
+	;; refill-stop should ideally be adjusted to
+	;; accomodate the "<br>" strings which are removed
+	;; between refill-start and refill-stop.  Can simply
+	;; be returned from my-replace-string
+	(setq refill-stop (+ (point)
+			     (html2text-replace-string
+			      "<br>" ""
+			      refill-start (point))))
+	;; (message "Point = %s  refill-stop = %s" (point) refill-stop)
+	;; (sleep-for 4)
+	(fill-region refill-start refill-stop))))
+  (html2text-replace-string "<br>" "" p1 p2))
 
 ;;
 ;; This one is interactive ...
@@ -452,7 +399,7 @@
 ;;
 
 (defun html2text-remove-tags (tag-list)
-  "Removes the tags listed in the list \"html2text-remove-tag-list\".
+  "Removes the tags listed in the list `html2text-remove-tag-list'.
 See the documentation for that variable."
   (interactive)
   (dolist (tag tag-list)
@@ -461,7 +408,7 @@
       (delete-region (match-beginning 0) (match-end 0)))))
 
 (defun html2text-format-tags ()
-  "See the variable \"html2text-format-tag-list\" for documentation"
+  "See the variable `html2text-format-tag-list' for documentation."
   (interactive)
   (dolist (tag-and-function html2text-format-tag-list)
     (let ((tag      (car tag-and-function))
@@ -480,27 +427,18 @@
 	  (search-backward "</" (point-min) t)
 	  (setq p3 (point))
 	  (funcall function p1 p2 p3 p4)
-	  (goto-char p1)
-	  )
-	)
-      )
-    )
-  )
+	  (goto-char p1))))))
 
 (defun html2text-substitute ()
-  "See the variable \"html2text-replace-list\" for documentation"
+  "See the variable `html2text-replace-list' for documentation."
   (interactive)
   (dolist (e html2text-replace-list)
     (goto-char (point-min))
     (let ((old-string (car e))
 	  (new-string (cdr e)))
-      (html2text-replace-string old-string new-string (point-min) (point-max))
-      )
-    )
-  )
+      (html2text-replace-string old-string new-string (point-min) (point-max)))))
 
 (defun html2text-format-single-elements ()
-  ""
   (interactive)
   (dolist (tag-and-function html2text-format-single-element-list)
     (let ((tag      (car tag-and-function))
@@ -512,12 +450,7 @@
 	      (p2 (point)))
 	  (search-backward "<" (point-min) t)
 	  (setq p1 (point))
-	  (funcall function p1 p2)
-	  )
-	)
-      )
-    )
-  )
+	  (funcall function p1 p2))))))
 
 ;;
 ;; Main function
@@ -540,6 +473,6 @@
 ;;
 ;; </Interactive functions>
 ;;
-
+(provide 'html2text)
 ;;; arch-tag: e9e57b79-35d4-4de1-a647-e7e01fe56d1e
 ;;; html2text.el ends here