Update copyright year to 2015
[gnus] / lisp / html2text.el
index 8cfd9b9..aef8063 100644 (file)
@@ -1,6 +1,6 @@
-;;; html2text.el --- a simple html to plain text converter
+;;; html2text.el --- a simple html to plain text converter -*- coding: utf-8 -*-
 
-;; Copyright (C) 2002-2011 Free Software Foundation, Inc.
+;; Copyright (C) 2002-2015 Free Software Foundation, Inc.
 
 ;; Author: Joakim Hove <hove@phys.ntnu.no>
 
     ("&ndash;" . "-")
     ("&permil;" . "%%")
     ("&plusmn;" . "+-")
-    ("&pound;" . "£")
+    ("&pound;" . "£")
     ("&quot;" . "\"")
     ("&raquo;" . ">>")
     ("&rdquo" . "\"")
     ("&reg;" . "(R)")
     ("&rsaquo;" . ")")
     ("&rsquo;" . "'")
-    ("&sect;" . "§")
+    ("&sect;" . "§")
     ("&sup1;" . "^1")
     ("&sup2;" . "^2")
     ("&sup3;" . "^3")
@@ -123,7 +123,7 @@ If this list contains the element \"font\".")
 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
 function is called with the arguments p1, p2, p3 and p4. These are
-demontrated below:
+demonstrated below:
 
 \"<b> This is bold text </b>\"
  ^   ^                 ^    ^
@@ -179,72 +179,20 @@ formatting, and then moved afterward.")
 
 (defun html2text-get-attr (p1 p2)
   (goto-char p1)
-  (re-search-forward " +[^ ]" p2 t)
-  (let* ((attr-string (buffer-substring-no-properties (1- (point)) (1- p2)))
-        (tmp-list (split-string attr-string))
-        (attr-list)
-        (counter 0)
-        (prev (car tmp-list))
-        (this (nth 1 tmp-list))
-        (next (nth 2 tmp-list))
-        (index 1))
-
-    (cond
-     ;; size=3
-     ((string-match "[^ ]=[^ ]" prev)
-      (let ((attr  (nth 0 (split-string prev "=")))
-           (value (substring prev (1+ (string-match "=" prev)))))
-       (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))))
-
-    (while (< index (length tmp-list))
-      (cond
-       ;; size=3
-       ((string-match "[^ ]=[^ ]" this)
-       (let ((attr  (nth 0 (split-string this "=")))
-             (value (substring prev (1+ (string-match "=" this)))))
-         (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)))
-       ;; size = 3
-       ((string= "=" this)
-       (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)))
-    ;;
-    ;; Tags with no accompanying "=" i.e. value=nil
-    ;;
-    (setq prev (car tmp-list))
-    (setq this (nth 1 tmp-list))
-    (setq next (nth 2 tmp-list))
-    (setq index 1)
-
-    (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)))
-      (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)))
-
-    (when (and this
-              (not (string-match "=" this))
-              (not (string= (substring prev -1) "=")))
-      (setq attr-list (cons (list this nil) attr-list)))
-    ;; return - value
+  (re-search-forward "\\s-+" p2 t)
+  (let (attr-list)
+    (while (re-search-forward "[-a-z0-9._]+" p2 t)
+      (setq attr-list
+           (cons
+            (list (match-string 0)
+                  (when (looking-at "\\s-*=")
+                    (goto-char (match-end 0))
+                    (skip-chars-forward "[:space:]")
+                    (when (or (looking-at "\"[^\"]*\"\\|'[^']*'")
+                              (looking-at "[-a-z0-9._:]+"))
+                      (goto-char (match-end 0))
+                      (match-string 0))))
+            attr-list)))
     attr-list))
 
 ;;
@@ -410,7 +358,7 @@ fashion, quite close to pure guess-work. It does work in some cases though."
   (while (re-search-forward "^<br>$" nil t)
     (delete-region (match-beginning 0) (match-end 0)))
   ;; Removing lonely <br> on a single line, if they are left intact we
-  ;; dont have any paragraphs at all.
+  ;; don't have any paragraphs at all.
   (goto-char (point-min))
   (while (not (eobp))
     (let ((p1 (point)))