diff options
| author | Karoly Lorentey | 2004-11-06 17:52:02 +0000 |
|---|---|---|
| committer | Karoly Lorentey | 2004-11-06 17:52:02 +0000 |
| commit | 65ea79492334e2ef7b5b4e0d23b6f68ba2f4d0bb (patch) | |
| tree | 853cf391ca1abda4f4ccd6fe8e7bb43f7c86ee08 /lisp/gnus/html2text.el | |
| parent | e0bc17abe6979d607e8de4684dddb96e53c60065 (diff) | |
| parent | 392cf16dd0ee9358f8af0cd0d8048b822456bbeb (diff) | |
| download | emacs-65ea79492334e2ef7b5b4e0d23b6f68ba2f4d0bb.tar.gz emacs-65ea79492334e2ef7b5b4e0d23b6f68ba2f4d0bb.zip | |
Merged in changes from CVS trunk.
Patches applied:
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-653
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-654
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-655
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-656
Update from CVS: lisp/man.el (Man-xref-normal-file): Fix help-echo.
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-657
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-658
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-659
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-660
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-661
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-662
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-663
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-664
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-665
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-666
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-667
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-668
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-669
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-670
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-671
Update from CVS
* miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-64
Update from CVS
* miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-65
Update from CVS
* miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-66
Update from CVS
* miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-67
Update from CVS
* miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-68
Update from CVS
git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-264
Diffstat (limited to 'lisp/gnus/html2text.el')
| -rw-r--r-- | lisp/gnus/html2text.el | 246 |
1 files changed, 89 insertions, 157 deletions
diff --git a/lisp/gnus/html2text.el b/lisp/gnus/html2text.el index 31d1869c695..ef05af9bae6 100644 --- a/lisp/gnus/html2text.el +++ b/lisp/gnus/html2text.el | |||
| @@ -24,11 +24,11 @@ | |||
| 24 | 24 | ||
| 25 | ;; These functions provide a simple way to wash/clean html infected | 25 | ;; These functions provide a simple way to wash/clean html infected |
| 26 | ;; mails. Definitely do not work in all cases, but some improvement | 26 | ;; mails. Definitely do not work in all cases, but some improvement |
| 27 | ;; in readability is generally obtained. Formatting is only done in | 27 | ;; in readability is generally obtained. Formatting is only done in |
| 28 | ;; the buffer, so the next time you enter the article it will be | 28 | ;; the buffer, so the next time you enter the article it will be |
| 29 | ;; "re-htmlized". | 29 | ;; "re-htmlized". |
| 30 | ;; | 30 | ;; |
| 31 | ;; The main function is "html2text" | 31 | ;; The main function is `html2text'. |
| 32 | 32 | ||
| 33 | ;;; Code: | 33 | ;;; Code: |
| 34 | 34 | ||
| @@ -47,9 +47,9 @@ | |||
| 47 | "The map of entity to text. | 47 | "The map of entity to text. |
| 48 | 48 | ||
| 49 | This is an alist were each element is a dotted pair consisting of an | 49 | This is an alist were each element is a dotted pair consisting of an |
| 50 | old string, and a replacement string. This replacement is done by the | 50 | old string, and a replacement string. This replacement is done by the |
| 51 | function \"html2text-substitute\" which basically performs a | 51 | function `html2text-substitute' which basically performs a |
| 52 | replace-string operation for every element in the list. This is | 52 | `replace-string' operation for every element in the list. This is |
| 53 | completely verbatim - without any use of REGEXP.") | 53 | completely verbatim - without any use of REGEXP.") |
| 54 | 54 | ||
| 55 | (defvar html2text-remove-tag-list | 55 | (defvar html2text-remove-tag-list |
| @@ -57,11 +57,11 @@ completely verbatim - without any use of REGEXP.") | |||
| 57 | "A list of removable tags. | 57 | "A list of removable tags. |
| 58 | 58 | ||
| 59 | This is a list of tags which should be removed, without any | 59 | This is a list of tags which should be removed, without any |
| 60 | formatting. Observe that if you the tags in the list are presented | 60 | formatting. Note that tags in the list are presented *without* |
| 61 | *without* any \"<\" or \">\". All occurences of a tag appearing in | 61 | any \"<\" or \">\". All occurences of a tag appearing in this |
| 62 | this list are removed, irrespective of whether it is a closing or | 62 | list are removed, irrespective of whether it is a closing or |
| 63 | opening tag, or if the tag has additional attributes. The actual | 63 | opening tag, or if the tag has additional attributes. The |
| 64 | deletion is done by the function \"html2text-remove-tags\". | 64 | deletion is done by the function `html2text-remove-tags'. |
| 65 | 65 | ||
| 66 | For instance the text: | 66 | For instance the text: |
| 67 | 67 | ||
| @@ -75,8 +75,10 @@ If this list contains the element \"font\".") | |||
| 75 | 75 | ||
| 76 | (defvar html2text-format-tag-list | 76 | (defvar html2text-format-tag-list |
| 77 | '(("b" . html2text-clean-bold) | 77 | '(("b" . html2text-clean-bold) |
| 78 | ("strong" . html2text-clean-bold) | ||
| 78 | ("u" . html2text-clean-underline) | 79 | ("u" . html2text-clean-underline) |
| 79 | ("i" . html2text-clean-italic) | 80 | ("i" . html2text-clean-italic) |
| 81 | ("em" . html2text-clean-italic) | ||
| 80 | ("blockquote" . html2text-clean-blockquote) | 82 | ("blockquote" . html2text-clean-blockquote) |
| 81 | ("a" . html2text-clean-anchor) | 83 | ("a" . html2text-clean-anchor) |
| 82 | ("ul" . html2text-clean-ul) | 84 | ("ul" . html2text-clean-ul) |
| @@ -86,7 +88,7 @@ If this list contains the element \"font\".") | |||
| 86 | "An alist of tags and processing functions. | 88 | "An alist of tags and processing functions. |
| 87 | 89 | ||
| 88 | This is an alist where each dotted pair consists of a tag, and then | 90 | This is an alist where each dotted pair consists of a tag, and then |
| 89 | the name of a function to be called when this tag is found. The | 91 | the name of a function to be called when this tag is found. The |
| 90 | function is called with the arguments p1, p2, p3 and p4. These are | 92 | function is called with the arguments p1, p2, p3 and p4. These are |
| 91 | demontrated below: | 93 | demontrated below: |
| 92 | 94 | ||
| @@ -117,17 +119,15 @@ formatting, and then moved afterward.") | |||
| 117 | ;; | 119 | ;; |
| 118 | 120 | ||
| 119 | 121 | ||
| 120 | (defun html2text-replace-string (from-string to-string p1 p2) | 122 | (defun html2text-replace-string (from-string to-string min max) |
| 121 | (goto-char p1) | 123 | "Replace FROM-STRING with TO-STRING in region from MIN to MAX." |
| 124 | (goto-char min) | ||
| 122 | (let ((delta (- (string-width to-string) (string-width from-string))) | 125 | (let ((delta (- (string-width to-string) (string-width from-string))) |
| 123 | (change 0)) | 126 | (change 0)) |
| 124 | (while (search-forward from-string p2 t) | 127 | (while (search-forward from-string max t) |
| 125 | (replace-match to-string) | 128 | (replace-match to-string) |
| 126 | (setq change (+ change delta)) | 129 | (setq change (+ change delta))) |
| 127 | ) | 130 | change)) |
| 128 | change | ||
| 129 | ) | ||
| 130 | ) | ||
| 131 | 131 | ||
| 132 | ;; | 132 | ;; |
| 133 | ;; </Utility functions> | 133 | ;; </Utility functions> |
| @@ -140,11 +140,11 @@ formatting, and then moved afterward.") | |||
| 140 | ;; <Functions related to attributes> i.e. <font size=+3> | 140 | ;; <Functions related to attributes> i.e. <font size=+3> |
| 141 | ;; | 141 | ;; |
| 142 | 142 | ||
| 143 | (defun html2text-attr-value (attr-list attr) | 143 | (defun html2text-attr-value (list attribute) |
| 144 | (nth 1 (assoc attr attr-list)) | 144 | "Get value of ATTRIBUTE from LIST." |
| 145 | ) | 145 | (nth 1 (assoc attribute list))) |
| 146 | 146 | ||
| 147 | (defun html2text-get-attr (p1 p2 tag) | 147 | (defun html2text-get-attr (p1 p2) |
| 148 | (goto-char p1) | 148 | (goto-char p1) |
| 149 | (re-search-forward " +[^ ]" p2 t) | 149 | (re-search-forward " +[^ ]" p2 t) |
| 150 | (let* ((attr-string (buffer-substring-no-properties (1- (point)) (1- p2))) | 150 | (let* ((attr-string (buffer-substring-no-properties (1- (point)) (1- p2))) |
| @@ -161,14 +161,10 @@ formatting, and then moved afterward.") | |||
| 161 | ((string-match "[^ ]=[^ ]" prev) | 161 | ((string-match "[^ ]=[^ ]" prev) |
| 162 | (let ((attr (nth 0 (split-string prev "="))) | 162 | (let ((attr (nth 0 (split-string prev "="))) |
| 163 | (value (nth 1 (split-string prev "=")))) | 163 | (value (nth 1 (split-string prev "=")))) |
| 164 | (setq attr-list (cons (list attr value) attr-list)) | 164 | (setq attr-list (cons (list attr value) attr-list)))) |
| 165 | ) | ||
| 166 | ) | ||
| 167 | ;; size= 3 | 165 | ;; size= 3 |
| 168 | ((string-match "[^ ]=\\'" prev) | 166 | ((string-match "[^ ]=\\'" prev) |
| 169 | (setq attr-list (cons (list (substring prev 0 -1) this) attr-list)) | 167 | (setq attr-list (cons (list (substring prev 0 -1) this) attr-list)))) |
| 170 | ) | ||
| 171 | ) | ||
| 172 | 168 | ||
| 173 | (while (< index (length tmp-list)) | 169 | (while (< index (length tmp-list)) |
| 174 | (cond | 170 | (cond |
| @@ -176,29 +172,20 @@ formatting, and then moved afterward.") | |||
| 176 | ((string-match "[^ ]=[^ ]" this) | 172 | ((string-match "[^ ]=[^ ]" this) |
| 177 | (let ((attr (nth 0 (split-string this "="))) | 173 | (let ((attr (nth 0 (split-string this "="))) |
| 178 | (value (nth 1 (split-string this "=")))) | 174 | (value (nth 1 (split-string this "=")))) |
| 179 | (setq attr-list (cons (list attr value) attr-list)) | 175 | (setq attr-list (cons (list attr value) attr-list)))) |
| 180 | ) | ||
| 181 | ) | ||
| 182 | ;; size =3 | 176 | ;; size =3 |
| 183 | ((string-match "\\`=[^ ]" this) | 177 | ((string-match "\\`=[^ ]" this) |
| 184 | (setq attr-list (cons (list prev (substring this 1)) attr-list))) | 178 | (setq attr-list (cons (list prev (substring this 1)) attr-list))) |
| 185 | |||
| 186 | ;; size= 3 | 179 | ;; size= 3 |
| 187 | ((string-match "[^ ]=\\'" this) | 180 | ((string-match "[^ ]=\\'" this) |
| 188 | (setq attr-list (cons (list (substring this 0 -1) next) attr-list)) | 181 | (setq attr-list (cons (list (substring this 0 -1) next) attr-list))) |
| 189 | ) | ||
| 190 | |||
| 191 | ;; size = 3 | 182 | ;; size = 3 |
| 192 | ((string= "=" this) | 183 | ((string= "=" this) |
| 193 | (setq attr-list (cons (list prev next) attr-list)) | 184 | (setq attr-list (cons (list prev next) attr-list)))) |
| 194 | ) | ||
| 195 | ) | ||
| 196 | (setq index (1+ index)) | 185 | (setq index (1+ index)) |
| 197 | (setq prev this) | 186 | (setq prev this) |
| 198 | (setq this next) | 187 | (setq this next) |
| 199 | (setq next (nth (1+ index) tmp-list)) | 188 | (setq next (nth (1+ index) tmp-list))) |
| 200 | ) | ||
| 201 | |||
| 202 | ;; | 189 | ;; |
| 203 | ;; Tags with no accompanying "=" i.e. value=nil | 190 | ;; Tags with no accompanying "=" i.e. value=nil |
| 204 | ;; | 191 | ;; |
| @@ -207,41 +194,25 @@ formatting, and then moved afterward.") | |||
| 207 | (setq next (nth 2 tmp-list)) | 194 | (setq next (nth 2 tmp-list)) |
| 208 | (setq index 1) | 195 | (setq index 1) |
| 209 | 196 | ||
| 210 | (if (not (string-match "=" prev)) | 197 | (when (and (not (string-match "=" prev)) |
| 211 | (progn | 198 | (not (string= (substring this 0 1) "="))) |
| 212 | (if (not (string= (substring this 0 1) "=")) | 199 | (setq attr-list (cons (list prev nil) attr-list))) |
| 213 | (setq attr-list (cons (list prev nil) attr-list)) | ||
| 214 | ) | ||
| 215 | ) | ||
| 216 | ) | ||
| 217 | |||
| 218 | (while (< index (1- (length tmp-list))) | 200 | (while (< index (1- (length tmp-list))) |
| 219 | (if (not (string-match "=" this)) | 201 | (when (and (not (string-match "=" this)) |
| 220 | (if (not (or (string= (substring next 0 1) "=") | 202 | (not (or (string= (substring next 0 1) "=") |
| 221 | (string= (substring prev -1) "="))) | 203 | (string= (substring prev -1) "=")))) |
| 222 | (setq attr-list (cons (list this nil) attr-list)) | 204 | (setq attr-list (cons (list this nil) attr-list))) |
| 223 | ) | ||
| 224 | ) | ||
| 225 | (setq index (1+ index)) | 205 | (setq index (1+ index)) |
| 226 | (setq prev this) | 206 | (setq prev this) |
| 227 | (setq this next) | 207 | (setq this next) |
| 228 | (setq next (nth (1+ index) tmp-list)) | 208 | (setq next (nth (1+ index) tmp-list))) |
| 229 | ) | 209 | |
| 230 | 210 | (when (and this | |
| 231 | (if this | 211 | (not (string-match "=" this)) |
| 232 | (progn | 212 | (not (string= (substring prev -1) "="))) |
| 233 | (if (not (string-match "=" this)) | 213 | (setq attr-list (cons (list this nil) attr-list))) |
| 234 | (progn | 214 | ;; return - value |
| 235 | (if (not (string= (substring prev -1) "=")) | 215 | attr-list)) |
| 236 | (setq attr-list (cons (list this nil) attr-list)) | ||
| 237 | ) | ||
| 238 | ) | ||
| 239 | ) | ||
| 240 | ) | ||
| 241 | ) | ||
| 242 | attr-list ;; return - value | ||
| 243 | ) | ||
| 244 | ) | ||
| 245 | 216 | ||
| 246 | ;; | 217 | ;; |
| 247 | ;; </Functions related to attributes> | 218 | ;; </Functions related to attributes> |
| @@ -266,10 +237,7 @@ formatting, and then moved afterward.") | |||
| 266 | (cond | 237 | (cond |
| 267 | ((string= list-type "ul") (insert " o ")) | 238 | ((string= list-type "ul") (insert " o ")) |
| 268 | ((string= list-type "ol") (insert (format " %s: " item-nr))) | 239 | ((string= list-type "ol") (insert (format " %s: " item-nr))) |
| 269 | (t (insert " x "))) | 240 | (t (insert " x ")))))) |
| 270 | ) | ||
| 271 | ) | ||
| 272 | ) | ||
| 273 | 241 | ||
| 274 | (defun html2text-clean-dtdd (p1 p2) | 242 | (defun html2text-clean-dtdd (p1 p2) |
| 275 | (goto-char p1) | 243 | (goto-char p1) |
| @@ -308,61 +276,51 @@ formatting, and then moved afterward.") | |||
| 308 | (html2text-delete-single-tag p1 p2) | 276 | (html2text-delete-single-tag p1 p2) |
| 309 | (goto-char p1) | 277 | (goto-char p1) |
| 310 | (newline 1) | 278 | (newline 1) |
| 311 | (insert (make-string fill-column ?-)) | 279 | (insert (make-string fill-column ?-))) |
| 312 | ) | ||
| 313 | 280 | ||
| 314 | (defun html2text-clean-ul (p1 p2 p3 p4) | 281 | (defun html2text-clean-ul (p1 p2 p3 p4) |
| 315 | (html2text-delete-tags p1 p2 p3 p4) | 282 | (html2text-delete-tags p1 p2 p3 p4) |
| 316 | (html2text-clean-list-items p1 (- p3 (- p1 p2)) "ul") | 283 | (html2text-clean-list-items p1 (- p3 (- p1 p2)) "ul")) |
| 317 | ) | ||
| 318 | 284 | ||
| 319 | (defun html2text-clean-ol (p1 p2 p3 p4) | 285 | (defun html2text-clean-ol (p1 p2 p3 p4) |
| 320 | (html2text-delete-tags p1 p2 p3 p4) | 286 | (html2text-delete-tags p1 p2 p3 p4) |
| 321 | (html2text-clean-list-items p1 (- p3 (- p1 p2)) "ol") | 287 | (html2text-clean-list-items p1 (- p3 (- p1 p2)) "ol")) |
| 322 | ) | ||
| 323 | 288 | ||
| 324 | (defun html2text-clean-dl (p1 p2 p3 p4) | 289 | (defun html2text-clean-dl (p1 p2 p3 p4) |
| 325 | (html2text-delete-tags p1 p2 p3 p4) | 290 | (html2text-delete-tags p1 p2 p3 p4) |
| 326 | (html2text-clean-dtdd p1 (- p3 (- p1 p2))) | 291 | (html2text-clean-dtdd p1 (- p3 (- p1 p2)))) |
| 327 | ) | ||
| 328 | 292 | ||
| 329 | (defun html2text-clean-center (p1 p2 p3 p4) | 293 | (defun html2text-clean-center (p1 p2 p3 p4) |
| 330 | (html2text-delete-tags p1 p2 p3 p4) | 294 | (html2text-delete-tags p1 p2 p3 p4) |
| 331 | (center-region p1 (- p3 (- p2 p1))) | 295 | (center-region p1 (- p3 (- p2 p1)))) |
| 332 | ) | ||
| 333 | 296 | ||
| 334 | (defun html2text-clean-bold (p1 p2 p3 p4) | 297 | (defun html2text-clean-bold (p1 p2 p3 p4) |
| 335 | (put-text-property p2 p3 'face 'bold) | 298 | (put-text-property p2 p3 'face 'bold) |
| 336 | (html2text-delete-tags p1 p2 p3 p4) | 299 | (html2text-delete-tags p1 p2 p3 p4)) |
| 337 | ) | ||
| 338 | 300 | ||
| 339 | (defun html2text-clean-title (p1 p2 p3 p4) | 301 | (defun html2text-clean-title (p1 p2 p3 p4) |
| 340 | (put-text-property p2 p3 'face 'bold) | 302 | (put-text-property p2 p3 'face 'bold) |
| 341 | (html2text-delete-tags p1 p2 p3 p4) | 303 | (html2text-delete-tags p1 p2 p3 p4)) |
| 342 | ) | ||
| 343 | 304 | ||
| 344 | (defun html2text-clean-underline (p1 p2 p3 p4) | 305 | (defun html2text-clean-underline (p1 p2 p3 p4) |
| 345 | (put-text-property p2 p3 'face 'underline) | 306 | (put-text-property p2 p3 'face 'underline) |
| 346 | (html2text-delete-tags p1 p2 p3 p4) | 307 | (html2text-delete-tags p1 p2 p3 p4)) |
| 347 | ) | ||
| 348 | 308 | ||
| 349 | (defun html2text-clean-italic (p1 p2 p3 p4) | 309 | (defun html2text-clean-italic (p1 p2 p3 p4) |
| 350 | (put-text-property p2 p3 'face 'italic) | 310 | (put-text-property p2 p3 'face 'italic) |
| 351 | (html2text-delete-tags p1 p2 p3 p4) | 311 | (html2text-delete-tags p1 p2 p3 p4)) |
| 352 | ) | ||
| 353 | 312 | ||
| 354 | (defun html2text-clean-font (p1 p2 p3 p4) | 313 | (defun html2text-clean-font (p1 p2 p3 p4) |
| 355 | (html2text-delete-tags p1 p2 p3 p4) | 314 | (html2text-delete-tags p1 p2 p3 p4)) |
| 356 | ) | ||
| 357 | 315 | ||
| 358 | (defun html2text-clean-blockquote (p1 p2 p3 p4) | 316 | (defun html2text-clean-blockquote (p1 p2 p3 p4) |
| 359 | (html2text-delete-tags p1 p2 p3 p4) | 317 | (html2text-delete-tags p1 p2 p3 p4)) |
| 360 | ) | ||
| 361 | 318 | ||
| 362 | (defun html2text-clean-anchor (p1 p2 p3 p4) | 319 | (defun html2text-clean-anchor (p1 p2 p3 p4) |
| 363 | ;; If someone can explain how to make the URL clickable I will | 320 | ;; If someone can explain how to make the URL clickable I will surely |
| 364 | ;; surely improve upon this. | 321 | ;; improve upon this. |
| 365 | (let* ((attr-list (html2text-get-attr p1 p2 "a")) | 322 | ;; Maybe `goto-addr.el' can be used here. |
| 323 | (let* ((attr-list (html2text-get-attr p1 p2)) | ||
| 366 | (href (html2text-attr-value attr-list "href"))) | 324 | (href (html2text-attr-value attr-list "href"))) |
| 367 | (delete-region p1 p4) | 325 | (delete-region p1 p4) |
| 368 | (when href | 326 | (when href |
| @@ -386,38 +344,27 @@ formatting, and then moved afterward.") | |||
| 386 | (let ((has-br-line) | 344 | (let ((has-br-line) |
| 387 | (refill-start) | 345 | (refill-start) |
| 388 | (refill-stop)) | 346 | (refill-stop)) |
| 389 | (if (re-search-forward "<br>$" p2 t) | 347 | (when (re-search-forward "<br>$" p2 t) |
| 390 | (setq has-br-line t) | 348 | (goto-char p1) |
| 391 | ) | 349 | (when (re-search-forward ".+[^<][^b][^r][^>]$" p2 t) |
| 392 | (if has-br-line | 350 | (beginning-of-line) |
| 393 | (progn | 351 | (setq refill-start (point)) |
| 394 | (goto-char p1) | 352 | (goto-char p2) |
| 395 | (if (re-search-forward ".+[^<][^b][^r][^>]$" p2 t) | 353 | (re-search-backward ".+[^<][^b][^r][^>]$" refill-start t) |
| 396 | (progn | 354 | (next-line 1) |
| 397 | (beginning-of-line) | 355 | (end-of-line) |
| 398 | (setq refill-start (point)) | 356 | ;; refill-stop should ideally be adjusted to |
| 399 | (goto-char p2) | 357 | ;; accomodate the "<br>" strings which are removed |
| 400 | (re-search-backward ".+[^<][^b][^r][^>]$" refill-start t) | 358 | ;; between refill-start and refill-stop. Can simply |
| 401 | (next-line 1) | 359 | ;; be returned from my-replace-string |
| 402 | (end-of-line) | 360 | (setq refill-stop (+ (point) |
| 403 | ;; refill-stop should ideally be adjusted to | 361 | (html2text-replace-string |
| 404 | ;; accomodate the "<br>" strings which are removed | 362 | "<br>" "" |
| 405 | ;; between refill-start and refill-stop. Can simply | 363 | refill-start (point)))) |
| 406 | ;; be returned from my-replace-string | 364 | ;; (message "Point = %s refill-stop = %s" (point) refill-stop) |
| 407 | (setq refill-stop (+ (point) | 365 | ;; (sleep-for 4) |
| 408 | (html2text-replace-string | 366 | (fill-region refill-start refill-stop)))) |
| 409 | "<br>" "" | 367 | (html2text-replace-string "<br>" "" p1 p2)) |
| 410 | refill-start (point)))) | ||
| 411 | ;; (message "Point = %s refill-stop = %s" (point) refill-stop) | ||
| 412 | ;; (sleep-for 4) | ||
| 413 | (fill-region refill-start refill-stop) | ||
| 414 | ) | ||
| 415 | ) | ||
| 416 | ) | ||
| 417 | ) | ||
| 418 | ) | ||
| 419 | (html2text-replace-string "<br>" "" p1 p2) | ||
| 420 | ) | ||
| 421 | 368 | ||
| 422 | ;; | 369 | ;; |
| 423 | ;; This one is interactive ... | 370 | ;; This one is interactive ... |
| @@ -452,7 +399,7 @@ fashion, quite close to pure guess-work. It does work in some cases though." | |||
| 452 | ;; | 399 | ;; |
| 453 | 400 | ||
| 454 | (defun html2text-remove-tags (tag-list) | 401 | (defun html2text-remove-tags (tag-list) |
| 455 | "Removes the tags listed in the list \"html2text-remove-tag-list\". | 402 | "Removes the tags listed in the list `html2text-remove-tag-list'. |
| 456 | See the documentation for that variable." | 403 | See the documentation for that variable." |
| 457 | (interactive) | 404 | (interactive) |
| 458 | (dolist (tag tag-list) | 405 | (dolist (tag tag-list) |
| @@ -461,7 +408,7 @@ See the documentation for that variable." | |||
| 461 | (delete-region (match-beginning 0) (match-end 0))))) | 408 | (delete-region (match-beginning 0) (match-end 0))))) |
| 462 | 409 | ||
| 463 | (defun html2text-format-tags () | 410 | (defun html2text-format-tags () |
| 464 | "See the variable \"html2text-format-tag-list\" for documentation" | 411 | "See the variable `html2text-format-tag-list' for documentation." |
| 465 | (interactive) | 412 | (interactive) |
| 466 | (dolist (tag-and-function html2text-format-tag-list) | 413 | (dolist (tag-and-function html2text-format-tag-list) |
| 467 | (let ((tag (car tag-and-function)) | 414 | (let ((tag (car tag-and-function)) |
| @@ -471,8 +418,7 @@ See the documentation for that variable." | |||
| 471 | (point-max) t) | 418 | (point-max) t) |
| 472 | (let ((p1) | 419 | (let ((p1) |
| 473 | (p2 (point)) | 420 | (p2 (point)) |
| 474 | (p3) (p4) | 421 | (p3) (p4)) |
| 475 | (attr (match-string 1))) | ||
| 476 | (search-backward "<" (point-min) t) | 422 | (search-backward "<" (point-min) t) |
| 477 | (setq p1 (point)) | 423 | (setq p1 (point)) |
| 478 | (re-search-forward (format "</%s>" tag) (point-max) t) | 424 | (re-search-forward (format "</%s>" tag) (point-max) t) |
| @@ -480,27 +426,18 @@ See the documentation for that variable." | |||
| 480 | (search-backward "</" (point-min) t) | 426 | (search-backward "</" (point-min) t) |
| 481 | (setq p3 (point)) | 427 | (setq p3 (point)) |
| 482 | (funcall function p1 p2 p3 p4) | 428 | (funcall function p1 p2 p3 p4) |
| 483 | (goto-char p1) | 429 | (goto-char p1)))))) |
| 484 | ) | ||
| 485 | ) | ||
| 486 | ) | ||
| 487 | ) | ||
| 488 | ) | ||
| 489 | 430 | ||
| 490 | (defun html2text-substitute () | 431 | (defun html2text-substitute () |
| 491 | "See the variable \"html2text-replace-list\" for documentation" | 432 | "See the variable `html2text-replace-list' for documentation." |
| 492 | (interactive) | 433 | (interactive) |
| 493 | (dolist (e html2text-replace-list) | 434 | (dolist (e html2text-replace-list) |
| 494 | (goto-char (point-min)) | 435 | (goto-char (point-min)) |
| 495 | (let ((old-string (car e)) | 436 | (let ((old-string (car e)) |
| 496 | (new-string (cdr e))) | 437 | (new-string (cdr e))) |
| 497 | (html2text-replace-string old-string new-string (point-min) (point-max)) | 438 | (html2text-replace-string old-string new-string (point-min) (point-max))))) |
| 498 | ) | ||
| 499 | ) | ||
| 500 | ) | ||
| 501 | 439 | ||
| 502 | (defun html2text-format-single-elements () | 440 | (defun html2text-format-single-elements () |
| 503 | "" | ||
| 504 | (interactive) | 441 | (interactive) |
| 505 | (dolist (tag-and-function html2text-format-single-element-list) | 442 | (dolist (tag-and-function html2text-format-single-element-list) |
| 506 | (let ((tag (car tag-and-function)) | 443 | (let ((tag (car tag-and-function)) |
| @@ -512,12 +449,7 @@ See the documentation for that variable." | |||
| 512 | (p2 (point))) | 449 | (p2 (point))) |
| 513 | (search-backward "<" (point-min) t) | 450 | (search-backward "<" (point-min) t) |
| 514 | (setq p1 (point)) | 451 | (setq p1 (point)) |
| 515 | (funcall function p1 p2) | 452 | (funcall function p1 p2)))))) |
| 516 | ) | ||
| 517 | ) | ||
| 518 | ) | ||
| 519 | ) | ||
| 520 | ) | ||
| 521 | 453 | ||
| 522 | ;; | 454 | ;; |
| 523 | ;; Main function | 455 | ;; Main function |
| @@ -540,6 +472,6 @@ See the documentation for that variable." | |||
| 540 | ;; | 472 | ;; |
| 541 | ;; </Interactive functions> | 473 | ;; </Interactive functions> |
| 542 | ;; | 474 | ;; |
| 543 | 475 | (provide 'html2text) | |
| 544 | ;;; arch-tag: e9e57b79-35d4-4de1-a647-e7e01fe56d1e | 476 | ;;; arch-tag: e9e57b79-35d4-4de1-a647-e7e01fe56d1e |
| 545 | ;;; html2text.el ends here | 477 | ;;; html2text.el ends here |