comparison lisp/gnus/html2text.el @ 91085:880960b70474

Merge from emacs--devo--0 Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-283
author Miles Bader <miles@gnu.org>
date Sun, 11 Nov 2007 00:56:44 +0000
parents a3c27999decb
children 107ccd98fa12
comparison
equal deleted inserted replaced
91084:a4347a111894 91085:880960b70474
41 (require 'cl)) 41 (require 'cl))
42 42
43 (defvar html2text-format-single-element-list '(("hr" . html2text-clean-hr))) 43 (defvar html2text-format-single-element-list '(("hr" . html2text-clean-hr)))
44 44
45 (defvar html2text-replace-list 45 (defvar html2text-replace-list
46 '(("&nbsp;" . " ") ("&gt;" . ">") ("&lt;" . "<") ("&quot;" . "\"") 46 '(("&acute;" . "`")
47 ("&amp;" . "&") ("&apos;" . "'")) 47 ("&amp;" . "&")
48 ("&apos;" . "'")
49 ("&brvbar;" . "|")
50 ("&cent;" . "c")
51 ("&circ;" . "^")
52 ("&copy;" . "(C)")
53 ("&curren;" . "(#)")
54 ("&deg;" . "degree")
55 ("&divide;" . "/")
56 ("&euro;" . "e")
57 ("&frac12;" . "1/2")
58 ("&gt;" . ">")
59 ("&iquest;" . "?")
60 ("&laquo;" . "<<")
61 ("&ldquo" . "\"")
62 ("&lsaquo;" . "(")
63 ("&lsquo;" . "`")
64 ("&lt;" . "<")
65 ("&mdash;" . "--")
66 ("&nbsp;" . " ")
67 ("&ndash;" . "-")
68 ("&permil;" . "%%")
69 ("&plusmn;" . "+-")
70 ("&pound;" . "£")
71 ("&quot;" . "\"")
72 ("&raquo;" . ">>")
73 ("&rdquo" . "\"")
74 ("&reg;" . "(R)")
75 ("&rsaquo;" . ")")
76 ("&rsquo;" . "'")
77 ("&sect;" . "§")
78 ("&sup1;" . "^1")
79 ("&sup2;" . "^2")
80 ("&sup3;" . "^3")
81 ("&tilde;" . "~"))
48 "The map of entity to text. 82 "The map of entity to text.
49 83
50 This is an alist were each element is a dotted pair consisting of an 84 This is an alist were each element is a dotted pair consisting of an
51 old string, and a replacement string. This replacement is done by the 85 old string, and a replacement string. This replacement is done by the
52 function `html2text-substitute' which basically performs a 86 function `html2text-substitute' which basically performs a
227 ;; 261 ;;
228 (defun html2text-clean-list-items (p1 p2 list-type) 262 (defun html2text-clean-list-items (p1 p2 list-type)
229 (goto-char p1) 263 (goto-char p1)
230 (let ((item-nr 0) 264 (let ((item-nr 0)
231 (items 0)) 265 (items 0))
232 (while (re-search-forward "<li>" p2 t) 266 (while (search-forward "<li>" p2 t)
233 (setq items (1+ items))) 267 (setq items (1+ items)))
234 (goto-char p1) 268 (goto-char p1)
235 (while (< item-nr items) 269 (while (< item-nr items)
236 (setq item-nr (1+ item-nr)) 270 (setq item-nr (1+ item-nr))
237 (re-search-forward "<li>" (point-max) t) 271 (search-forward "<li>" (point-max) t)
238 (cond 272 (cond
239 ((string= list-type "ul") (insert " o ")) 273 ((string= list-type "ul") (insert " o "))
240 ((string= list-type "ol") (insert (format " %s: " item-nr))) 274 ((string= list-type "ol") (insert (format " %s: " item-nr)))
241 (t (insert " x ")))))) 275 (t (insert " x "))))))
242 276
243 (defun html2text-clean-dtdd (p1 p2) 277 (defun html2text-clean-dtdd (p1 p2)
244 (goto-char p1) 278 (goto-char p1)
245 (let ((items 0) 279 (let ((items 0)
246 (item-nr 0)) 280 (item-nr 0))
247 (while (re-search-forward "<dt>" p2 t) 281 (while (search-forward "<dt>" p2 t)
248 (setq items (1+ items))) 282 (setq items (1+ items)))
249 (goto-char p1) 283 (goto-char p1)
250 (while (< item-nr items) 284 (while (< item-nr items)
251 (setq item-nr (1+ item-nr)) 285 (setq item-nr (1+ item-nr))
252 (re-search-forward "<dt>\\([ ]*\\)" (point-max) t) 286 (re-search-forward "<dt>\\([ ]*\\)" (point-max) t)
340 ;; <Functions to be called to fix up paragraphs> 374 ;; <Functions to be called to fix up paragraphs>
341 ;; 375 ;;
342 376
343 (defun html2text-fix-paragraph (p1 p2) 377 (defun html2text-fix-paragraph (p1 p2)
344 (goto-char p1) 378 (goto-char p1)
345 (let ((has-br-line) 379 (let ((refill-start)
346 (refill-start)
347 (refill-stop)) 380 (refill-stop))
348 (when (re-search-forward "<br>$" p2 t) 381 (when (re-search-forward "<br>$" p2 t)
349 (goto-char p1) 382 (goto-char p1)
350 (when (re-search-forward ".+[^<][^b][^r][^>]$" p2 t) 383 (when (re-search-forward ".+[^<][^b][^r][^>]$" p2 t)
351 (beginning-of-line) 384 (beginning-of-line)