;;; html2text.el --- a simple html to plain text converter
-;; Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+
+;; Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
;; Author: Joakim Hove <hove@phys.ntnu.no>
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
;;; Commentary:
(defvar html2text-format-single-element-list '(("hr" . html2text-clean-hr)))
(defvar html2text-replace-list
- '((" " . " ") (">" . ">") ("<" . "<") (""" . "\"")
- ("&" . "&") ("'" . "'"))
+ '(("´" . "`")
+ ("&" . "&")
+ ("'" . "'")
+ ("¦" . "|")
+ ("¢" . "c")
+ ("ˆ" . "^")
+ ("©" . "(C)")
+ ("¤" . "(#)")
+ ("°" . "degree")
+ ("÷" . "/")
+ ("€" . "e")
+ ("½" . "1/2")
+ (">" . ">")
+ ("¿" . "?")
+ ("«" . "<<")
+ ("&ldquo" . "\"")
+ ("‹" . "(")
+ ("‘" . "`")
+ ("<" . "<")
+ ("—" . "--")
+ (" " . " ")
+ ("–" . "-")
+ ("‰" . "%%")
+ ("±" . "+-")
+ ("£" . "£")
+ (""" . "\"")
+ ("»" . ">>")
+ ("&rdquo" . "\"")
+ ("®" . "(R)")
+ ("›" . ")")
+ ("’" . "'")
+ ("§" . "§")
+ ("¹" . "^1")
+ ("²" . "^2")
+ ("³" . "^3")
+ ("˜" . "~"))
"The map of entity to text.
This is an alist were each element is a dotted pair consisting of an
This is a list of tags which should be removed, without any
formatting. Note that tags in the list are presented *without*
-any \"<\" or \">\". All occurences of a tag appearing in this
+any \"<\" or \">\". All occurrences 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'.
"Get value of ATTRIBUTE from LIST."
(nth 1 (assoc attribute list)))
-(defun html2text-get-attr (p1 p2 tag)
+(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)))
;; 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"))
+ (let* ((attr-list (html2text-get-attr p1 p2))
(href (html2text-attr-value attr-list "href")))
(delete-region p1 p4)
(when href
fashion, quite close to pure guess-work. It does work in some cases though."
(interactive)
(goto-char (point-min))
- (replace-regexp "^<br>$" "")
+ (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.
(goto-char (point-min))
(point-max) t)
(let ((p1)
(p2 (point))
- (p3) (p4)
- (attr (match-string 0)))
+ (p3) (p4))
(search-backward "<" (point-min) t)
(setq p1 (point))
(search-forward (format "</%s>" tag) (point-max) t)