Mercurial > emacs
annotate lisp/gnus/shr.el @ 111325:9aff83bb4de1
* lisp/progmodes/perl-mode.el (perl-syntax-propertize-function):
Handle __DATA__ and __END__.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Tue, 02 Nov 2010 22:30:12 -0400 |
parents | 131f7940cd0f |
children | 969fb8574065 |
rev | line source |
---|---|
110698
74bad2d7bddd
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
1 ;;; shr.el --- Simple HTML Renderer |
74bad2d7bddd
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
2 |
74bad2d7bddd
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
3 ;; Copyright (C) 2010 Free Software Foundation, Inc. |
74bad2d7bddd
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
4 |
74bad2d7bddd
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org> |
74bad2d7bddd
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
6 ;; Keywords: html |
74bad2d7bddd
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
7 |
74bad2d7bddd
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
8 ;; This file is part of GNU Emacs. |
74bad2d7bddd
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
9 |
74bad2d7bddd
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
10 ;; GNU Emacs is free software: you can redistribute it and/or modify |
74bad2d7bddd
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
11 ;; it under the terms of the GNU General Public License as published by |
74bad2d7bddd
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
12 ;; the Free Software Foundation, either version 3 of the License, or |
74bad2d7bddd
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
13 ;; (at your option) any later version. |
74bad2d7bddd
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
14 |
74bad2d7bddd
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
15 ;; GNU Emacs is distributed in the hope that it will be useful, |
74bad2d7bddd
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
74bad2d7bddd
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
74bad2d7bddd
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
18 ;; GNU General Public License for more details. |
74bad2d7bddd
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
19 |
74bad2d7bddd
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
20 ;; You should have received a copy of the GNU General Public License |
74bad2d7bddd
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
74bad2d7bddd
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
22 |
74bad2d7bddd
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
23 ;;; Commentary: |
74bad2d7bddd
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
24 |
74bad2d7bddd
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
25 ;; This package takes a HTML parse tree (as provided by |
74bad2d7bddd
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
26 ;; libxml-parse-html-region) and renders it in the current buffer. It |
74bad2d7bddd
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
27 ;; does not do CSS, JavaScript or anything advanced: It's geared |
74bad2d7bddd
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
28 ;; towards rendering typical short snippets of HTML, like what you'd |
74bad2d7bddd
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
29 ;; find in HTML email and the like. |
74bad2d7bddd
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
30 |
74bad2d7bddd
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
31 ;;; Code: |
74bad2d7bddd
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
32 |
110810
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
33 (eval-when-compile (require 'cl)) |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
34 (require 'browse-url) |
111033
8ad626575f8a
shr.el: Fix last change.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111032
diff
changeset
|
35 (unless (aref (char-category-set (make-char 'japanese-jisx0208 33 35)) ?>) |
8ad626575f8a
shr.el: Fix last change.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111032
diff
changeset
|
36 (load "kinsoku" nil t)) |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
37 |
110708
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
38 (defgroup shr nil |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
39 "Simple HTML Renderer" |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
40 :group 'mail) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
41 |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
42 (defcustom shr-max-image-proportion 0.9 |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
43 "How big pictures displayed are in relation to the window they're in. |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
44 A value of 0.7 means that they are allowed to take up 70% of the |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
45 width and height of the window. If they are larger than this, |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
46 and Emacs supports it, then the images will be rescaled down to |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
47 fit these criteria." |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
48 :version "24.1" |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
49 :group 'shr |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
50 :type 'float) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
51 |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
52 (defcustom shr-blocked-images nil |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
53 "Images that have URLs matching this regexp will be blocked." |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
54 :version "24.1" |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
55 :group 'shr |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
56 :type 'regexp) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
57 |
110873
d98a67277730
shr,el: Allow shr table char to be customized.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110859
diff
changeset
|
58 (defcustom shr-table-line ?- |
d98a67277730
shr,el: Allow shr table char to be customized.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110859
diff
changeset
|
59 "Character used to draw table line." |
d98a67277730
shr,el: Allow shr table char to be customized.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110859
diff
changeset
|
60 :group 'shr |
110999
9330a5183ae6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110996
diff
changeset
|
61 :type 'character) |
110873
d98a67277730
shr,el: Allow shr table char to be customized.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110859
diff
changeset
|
62 |
d98a67277730
shr,el: Allow shr table char to be customized.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110859
diff
changeset
|
63 (defcustom shr-table-corner ?+ |
110917
3243e7055d49
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110898
diff
changeset
|
64 "Character used to draw table corner." |
3243e7055d49
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110898
diff
changeset
|
65 :group 'shr |
110999
9330a5183ae6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110996
diff
changeset
|
66 :type 'character) |
110917
3243e7055d49
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110898
diff
changeset
|
67 |
3243e7055d49
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110898
diff
changeset
|
68 (defcustom shr-hr-line ?- |
3243e7055d49
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110898
diff
changeset
|
69 "Character used to draw hr line." |
110873
d98a67277730
shr,el: Allow shr table char to be customized.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110859
diff
changeset
|
70 :group 'shr |
110999
9330a5183ae6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110996
diff
changeset
|
71 :type 'character) |
110873
d98a67277730
shr,el: Allow shr table char to be customized.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110859
diff
changeset
|
72 |
110966
0272ba632fc2
shr: make shr-width a defcustom, use it in shr-tag-img.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110957
diff
changeset
|
73 (defcustom shr-width fill-column |
0272ba632fc2
shr: make shr-width a defcustom, use it in shr-tag-img.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110957
diff
changeset
|
74 "Frame width to use for rendering." |
0272ba632fc2
shr: make shr-width a defcustom, use it in shr-tag-img.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110957
diff
changeset
|
75 :type 'integer |
0272ba632fc2
shr: make shr-width a defcustom, use it in shr-tag-img.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110957
diff
changeset
|
76 :group 'shr) |
0272ba632fc2
shr: make shr-width a defcustom, use it in shr-tag-img.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110957
diff
changeset
|
77 |
110777
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
78 (defvar shr-content-function nil |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
79 "If bound, this should be a function that will return the content. |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
80 This is used for cid: URLs, and the function is called with the |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
81 cid: URL as the argument.") |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
82 |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
83 ;;; Internal variables. |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
84 |
110708
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
85 (defvar shr-folding-mode nil) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
86 (defvar shr-state nil) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
87 (defvar shr-start nil) |
110747
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
88 (defvar shr-indentation 0) |
110777
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
89 (defvar shr-inhibit-images nil) |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
90 (defvar shr-list-mode nil) |
110810
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
91 (defvar shr-content-cache nil) |
111032
1ed05f12a0bc
shr.el: Improve kinsoku and table rendering.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111022
diff
changeset
|
92 (defvar shr-kinsoku-shorten nil) |
111240
ffb890b32d37
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111218
diff
changeset
|
93 (defvar shr-table-depth 0) |
110708
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
94 |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
95 (defvar shr-map |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
96 (let ((map (make-sparse-keymap))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
97 (define-key map "a" 'shr-show-alt-text) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
98 (define-key map "i" 'shr-browse-image) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
99 (define-key map "I" 'shr-insert-image) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
100 (define-key map "u" 'shr-copy-url) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
101 (define-key map "v" 'shr-browse-url) |
111058
ea17726e9043
shr.el (shr-save-contents): New command and keystroke.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111057
diff
changeset
|
102 (define-key map "o" 'shr-save-contents) |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
103 (define-key map "\r" 'shr-browse-url) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
104 map)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
105 |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
106 ;; Public functions and commands. |
110708
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
107 |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
108 ;;;###autoload |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
109 (defun shr-insert-document (dom) |
110810
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
110 (setq shr-content-cache nil) |
110708
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
111 (let ((shr-state nil) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
112 (shr-start nil)) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
113 (shr-descend (shr-transform-dom dom)))) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
114 |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
115 (defun shr-copy-url () |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
116 "Copy the URL under point to the kill ring. |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
117 If called twice, then try to fetch the URL and see whether it |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
118 redirects somewhere else." |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
119 (interactive) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
120 (let ((url (get-text-property (point) 'shr-url))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
121 (cond |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
122 ((not url) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
123 (message "No URL under point")) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
124 ;; Resolve redirected URLs. |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
125 ((equal url (car kill-ring)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
126 (url-retrieve |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
127 url |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
128 (lambda (a) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
129 (when (and (consp a) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
130 (eq (car a) :redirect)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
131 (with-temp-buffer |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
132 (insert (cadr a)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
133 (goto-char (point-min)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
134 ;; Remove common tracking junk from the URL. |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
135 (when (re-search-forward ".utm_.*" nil t) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
136 (replace-match "" t t)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
137 (message "Copied %s" (buffer-string)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
138 (copy-region-as-kill (point-min) (point-max))))))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
139 ;; Copy the URL to the kill ring. |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
140 (t |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
141 (with-temp-buffer |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
142 (insert url) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
143 (copy-region-as-kill (point-min) (point-max)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
144 (message "Copied %s" url)))))) |
110708
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
145 |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
146 (defun shr-show-alt-text () |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
147 "Show the ALT text of the image under point." |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
148 (interactive) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
149 (let ((text (get-text-property (point) 'shr-alt))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
150 (if (not text) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
151 (message "No image under point") |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
152 (message "%s" text)))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
153 |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
154 (defun shr-browse-image () |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
155 "Browse the image under point." |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
156 (interactive) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
157 (let ((url (get-text-property (point) 'shr-image))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
158 (if (not url) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
159 (message "No image under point") |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
160 (message "Browsing %s..." url) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
161 (browse-url url)))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
162 |
110810
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
163 (defun shr-insert-image () |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
164 "Insert the image under point into the buffer." |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
165 (interactive) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
166 (let ((url (get-text-property (point) 'shr-image))) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
167 (if (not url) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
168 (message "No image under point") |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
169 (message "Inserting %s..." url) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
170 (url-retrieve url 'shr-image-fetched |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
171 (list (current-buffer) (1- (point)) (point-marker)) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
172 t)))) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
173 |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
174 ;;; Utility functions. |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
175 |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
176 (defun shr-transform-dom (dom) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
177 (let ((result (list (pop dom)))) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
178 (dolist (arg (pop dom)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
179 (push (cons (intern (concat ":" (symbol-name (car arg))) obarray) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
180 (cdr arg)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
181 result)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
182 (dolist (sub dom) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
183 (if (stringp sub) |
111245
dd1304e89176
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111240
diff
changeset
|
184 (push (cons 'text sub) result) |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
185 (push (shr-transform-dom sub) result))) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
186 (nreverse result))) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
187 |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
188 (defun shr-descend (dom) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
189 (let ((function (intern (concat "shr-tag-" (symbol-name (car dom))) obarray))) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
190 (if (fboundp function) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
191 (funcall function (cdr dom)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
192 (shr-generic (cdr dom))))) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
193 |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
194 (defun shr-generic (cont) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
195 (dolist (sub cont) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
196 (cond |
111245
dd1304e89176
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111240
diff
changeset
|
197 ((eq (car sub) 'text) |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
198 (shr-insert (cdr sub))) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
199 ((listp (cdr sub)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
200 (shr-descend sub))))) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
201 |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
202 (defun shr-insert (text) |
110917
3243e7055d49
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110898
diff
changeset
|
203 (when (and (eq shr-state 'image) |
3243e7055d49
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110898
diff
changeset
|
204 (not (string-match "\\`[ \t\n]+\\'" text))) |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
205 (insert "\n") |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
206 (setq shr-state nil)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
207 (cond |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
208 ((eq shr-folding-mode 'none) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
209 (insert text)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
210 (t |
111021
7aa9d9b402c8
shr.el (shr-insert): Don't insert space behind a wide character categorized as kinsoku-bol, or between characters both categorized as nospace.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111019
diff
changeset
|
211 (when (and (string-match "\\`[ \t\n]" text) |
7aa9d9b402c8
shr.el (shr-insert): Don't insert space behind a wide character categorized as kinsoku-bol, or between characters both categorized as nospace.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111019
diff
changeset
|
212 (not (bolp)) |
7aa9d9b402c8
shr.el (shr-insert): Don't insert space behind a wide character categorized as kinsoku-bol, or between characters both categorized as nospace.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111019
diff
changeset
|
213 (not (eq (char-after (1- (point))) ? ))) |
7aa9d9b402c8
shr.el (shr-insert): Don't insert space behind a wide character categorized as kinsoku-bol, or between characters both categorized as nospace.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111019
diff
changeset
|
214 (insert " ")) |
7aa9d9b402c8
shr.el (shr-insert): Don't insert space behind a wide character categorized as kinsoku-bol, or between characters both categorized as nospace.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111019
diff
changeset
|
215 (dolist (elem (split-string text)) |
7aa9d9b402c8
shr.el (shr-insert): Don't insert space behind a wide character categorized as kinsoku-bol, or between characters both categorized as nospace.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111019
diff
changeset
|
216 (when (and (bolp) |
7aa9d9b402c8
shr.el (shr-insert): Don't insert space behind a wide character categorized as kinsoku-bol, or between characters both categorized as nospace.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111019
diff
changeset
|
217 (> shr-indentation 0)) |
7aa9d9b402c8
shr.el (shr-insert): Don't insert space behind a wide character categorized as kinsoku-bol, or between characters both categorized as nospace.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111019
diff
changeset
|
218 (shr-indent)) |
7aa9d9b402c8
shr.el (shr-insert): Don't insert space behind a wide character categorized as kinsoku-bol, or between characters both categorized as nospace.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111019
diff
changeset
|
219 ;; The shr-start is a special variable that is used to pass |
7aa9d9b402c8
shr.el (shr-insert): Don't insert space behind a wide character categorized as kinsoku-bol, or between characters both categorized as nospace.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111019
diff
changeset
|
220 ;; upwards the first point in the buffer where the text really |
7aa9d9b402c8
shr.el (shr-insert): Don't insert space behind a wide character categorized as kinsoku-bol, or between characters both categorized as nospace.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111019
diff
changeset
|
221 ;; starts. |
7aa9d9b402c8
shr.el (shr-insert): Don't insert space behind a wide character categorized as kinsoku-bol, or between characters both categorized as nospace.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111019
diff
changeset
|
222 (unless shr-start |
7aa9d9b402c8
shr.el (shr-insert): Don't insert space behind a wide character categorized as kinsoku-bol, or between characters both categorized as nospace.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111019
diff
changeset
|
223 (setq shr-start (point))) |
7aa9d9b402c8
shr.el (shr-insert): Don't insert space behind a wide character categorized as kinsoku-bol, or between characters both categorized as nospace.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111019
diff
changeset
|
224 ;; No space is needed behind a wide character categorized as |
111022
d263303441df
shr.el (shr-insert): Comment fix.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111021
diff
changeset
|
225 ;; kinsoku-bol, between characters both categorized as nospace, |
d263303441df
shr.el (shr-insert): Comment fix.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111021
diff
changeset
|
226 ;; or at the beginning of a line. |
111021
7aa9d9b402c8
shr.el (shr-insert): Don't insert space behind a wide character categorized as kinsoku-bol, or between characters both categorized as nospace.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111019
diff
changeset
|
227 (let (prev) |
111002
62243368de05
shr.el (shr-insert): Remove space inserted before or after a breakable character or at the beginning or the end of a line.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110999
diff
changeset
|
228 (when (and (eq (preceding-char) ? ) |
62243368de05
shr.el (shr-insert): Remove space inserted before or after a breakable character or at the beginning or the end of a line.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110999
diff
changeset
|
229 (or (= (line-beginning-position) (1- (point))) |
111021
7aa9d9b402c8
shr.el (shr-insert): Don't insert space behind a wide character categorized as kinsoku-bol, or between characters both categorized as nospace.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111019
diff
changeset
|
230 (and (aref fill-find-break-point-function-table |
7aa9d9b402c8
shr.el (shr-insert): Don't insert space behind a wide character categorized as kinsoku-bol, or between characters both categorized as nospace.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111019
diff
changeset
|
231 (setq prev (char-after (- (point) 2)))) |
7aa9d9b402c8
shr.el (shr-insert): Don't insert space behind a wide character categorized as kinsoku-bol, or between characters both categorized as nospace.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111019
diff
changeset
|
232 (aref (char-category-set prev) ?>)) |
7aa9d9b402c8
shr.el (shr-insert): Don't insert space behind a wide character categorized as kinsoku-bol, or between characters both categorized as nospace.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111019
diff
changeset
|
233 (and (aref fill-nospace-between-words-table prev) |
7aa9d9b402c8
shr.el (shr-insert): Don't insert space behind a wide character categorized as kinsoku-bol, or between characters both categorized as nospace.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111019
diff
changeset
|
234 (aref fill-nospace-between-words-table |
7aa9d9b402c8
shr.el (shr-insert): Don't insert space behind a wide character categorized as kinsoku-bol, or between characters both categorized as nospace.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111019
diff
changeset
|
235 (aref elem 0))))) |
7aa9d9b402c8
shr.el (shr-insert): Don't insert space behind a wide character categorized as kinsoku-bol, or between characters both categorized as nospace.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111019
diff
changeset
|
236 (delete-char -1))) |
7aa9d9b402c8
shr.el (shr-insert): Don't insert space behind a wide character categorized as kinsoku-bol, or between characters both categorized as nospace.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111019
diff
changeset
|
237 (insert elem) |
7aa9d9b402c8
shr.el (shr-insert): Don't insert space behind a wide character categorized as kinsoku-bol, or between characters both categorized as nospace.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111019
diff
changeset
|
238 (while (> (current-column) shr-width) |
7aa9d9b402c8
shr.el (shr-insert): Don't insert space behind a wide character categorized as kinsoku-bol, or between characters both categorized as nospace.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111019
diff
changeset
|
239 (unless (prog1 |
7aa9d9b402c8
shr.el (shr-insert): Don't insert space behind a wide character categorized as kinsoku-bol, or between characters both categorized as nospace.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111019
diff
changeset
|
240 (shr-find-fill-point) |
7aa9d9b402c8
shr.el (shr-insert): Don't insert space behind a wide character categorized as kinsoku-bol, or between characters both categorized as nospace.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111019
diff
changeset
|
241 (when (eq (preceding-char) ? ) |
7aa9d9b402c8
shr.el (shr-insert): Don't insert space behind a wide character categorized as kinsoku-bol, or between characters both categorized as nospace.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111019
diff
changeset
|
242 (delete-char -1)) |
7aa9d9b402c8
shr.el (shr-insert): Don't insert space behind a wide character categorized as kinsoku-bol, or between characters both categorized as nospace.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111019
diff
changeset
|
243 (insert "\n")) |
7aa9d9b402c8
shr.el (shr-insert): Don't insert space behind a wide character categorized as kinsoku-bol, or between characters both categorized as nospace.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111019
diff
changeset
|
244 (put-text-property (1- (point)) (point) 'shr-break t) |
7aa9d9b402c8
shr.el (shr-insert): Don't insert space behind a wide character categorized as kinsoku-bol, or between characters both categorized as nospace.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111019
diff
changeset
|
245 ;; No space is needed at the beginning of a line. |
111057
097fe1170a9a
shr.el (shr-find-fill-point): Don't leave blanks at the start of some lines.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111054
diff
changeset
|
246 (when (eq (following-char) ? ) |
097fe1170a9a
shr.el (shr-find-fill-point): Don't leave blanks at the start of some lines.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111054
diff
changeset
|
247 (delete-char 1))) |
111021
7aa9d9b402c8
shr.el (shr-insert): Don't insert space behind a wide character categorized as kinsoku-bol, or between characters both categorized as nospace.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111019
diff
changeset
|
248 (when (> shr-indentation 0) |
7aa9d9b402c8
shr.el (shr-insert): Don't insert space behind a wide character categorized as kinsoku-bol, or between characters both categorized as nospace.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111019
diff
changeset
|
249 (shr-indent)) |
7aa9d9b402c8
shr.el (shr-insert): Don't insert space behind a wide character categorized as kinsoku-bol, or between characters both categorized as nospace.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111019
diff
changeset
|
250 (end-of-line)) |
7aa9d9b402c8
shr.el (shr-insert): Don't insert space behind a wide character categorized as kinsoku-bol, or between characters both categorized as nospace.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111019
diff
changeset
|
251 (insert " ")) |
7aa9d9b402c8
shr.el (shr-insert): Don't insert space behind a wide character categorized as kinsoku-bol, or between characters both categorized as nospace.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111019
diff
changeset
|
252 (unless (string-match "[ \t\n]\\'" text) |
7aa9d9b402c8
shr.el (shr-insert): Don't insert space behind a wide character categorized as kinsoku-bol, or between characters both categorized as nospace.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111019
diff
changeset
|
253 (delete-char -1))))) |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
254 |
110917
3243e7055d49
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110898
diff
changeset
|
255 (defun shr-find-fill-point () |
111032
1ed05f12a0bc
shr.el: Improve kinsoku and table rendering.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111022
diff
changeset
|
256 (when (> (move-to-column shr-width) shr-width) |
1ed05f12a0bc
shr.el: Improve kinsoku and table rendering.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111022
diff
changeset
|
257 (backward-char 1)) |
1ed05f12a0bc
shr.el: Improve kinsoku and table rendering.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111022
diff
changeset
|
258 (let (failed) |
1ed05f12a0bc
shr.el: Improve kinsoku and table rendering.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111022
diff
changeset
|
259 (while (not |
1ed05f12a0bc
shr.el: Improve kinsoku and table rendering.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111022
diff
changeset
|
260 (or (setq failed (= (current-column) shr-indentation)) |
1ed05f12a0bc
shr.el: Improve kinsoku and table rendering.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111022
diff
changeset
|
261 (eq (preceding-char) ? ) |
1ed05f12a0bc
shr.el: Improve kinsoku and table rendering.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111022
diff
changeset
|
262 (eq (following-char) ? ) |
1ed05f12a0bc
shr.el: Improve kinsoku and table rendering.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111022
diff
changeset
|
263 (aref fill-find-break-point-function-table (preceding-char)))) |
1ed05f12a0bc
shr.el: Improve kinsoku and table rendering.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111022
diff
changeset
|
264 (backward-char 1)) |
1ed05f12a0bc
shr.el: Improve kinsoku and table rendering.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111022
diff
changeset
|
265 (if failed |
111002
62243368de05
shr.el (shr-insert): Remove space inserted before or after a breakable character or at the beginning or the end of a line.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110999
diff
changeset
|
266 ;; There's no breakable point, so we give it up. |
111032
1ed05f12a0bc
shr.el: Improve kinsoku and table rendering.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111022
diff
changeset
|
267 (progn |
1ed05f12a0bc
shr.el: Improve kinsoku and table rendering.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111022
diff
changeset
|
268 (end-of-line) |
1ed05f12a0bc
shr.el: Improve kinsoku and table rendering.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111022
diff
changeset
|
269 (while (aref fill-find-break-point-function-table (preceding-char)) |
1ed05f12a0bc
shr.el: Improve kinsoku and table rendering.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111022
diff
changeset
|
270 (backward-char 1)) |
1ed05f12a0bc
shr.el: Improve kinsoku and table rendering.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111022
diff
changeset
|
271 nil) |
1ed05f12a0bc
shr.el: Improve kinsoku and table rendering.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111022
diff
changeset
|
272 (or (eolp) |
1ed05f12a0bc
shr.el: Improve kinsoku and table rendering.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111022
diff
changeset
|
273 ;; Don't put kinsoku-bol characters at the beginning of a line, |
1ed05f12a0bc
shr.el: Improve kinsoku and table rendering.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111022
diff
changeset
|
274 ;; or kinsoku-eol characters at the end of a line, |
1ed05f12a0bc
shr.el: Improve kinsoku and table rendering.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111022
diff
changeset
|
275 (let ((count 4)) |
111059
938faaa83cf1
shr.el (shr-find-fill-point): Shorten line if the preceding char is kinsoku-eol regardless of shr-kinsoku-shorten.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111058
diff
changeset
|
276 (if (or shr-kinsoku-shorten |
938faaa83cf1
shr.el (shr-find-fill-point): Shorten line if the preceding char is kinsoku-eol regardless of shr-kinsoku-shorten.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111058
diff
changeset
|
277 (and (aref (char-category-set (preceding-char)) ?<) |
938faaa83cf1
shr.el (shr-find-fill-point): Shorten line if the preceding char is kinsoku-eol regardless of shr-kinsoku-shorten.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111058
diff
changeset
|
278 (progn |
938faaa83cf1
shr.el (shr-find-fill-point): Shorten line if the preceding char is kinsoku-eol regardless of shr-kinsoku-shorten.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111058
diff
changeset
|
279 (setq count (1- count)) |
938faaa83cf1
shr.el (shr-find-fill-point): Shorten line if the preceding char is kinsoku-eol regardless of shr-kinsoku-shorten.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111058
diff
changeset
|
280 (backward-char 1) |
938faaa83cf1
shr.el (shr-find-fill-point): Shorten line if the preceding char is kinsoku-eol regardless of shr-kinsoku-shorten.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111058
diff
changeset
|
281 t))) |
111032
1ed05f12a0bc
shr.el: Improve kinsoku and table rendering.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111022
diff
changeset
|
282 (while (and |
111059
938faaa83cf1
shr.el (shr-find-fill-point): Shorten line if the preceding char is kinsoku-eol regardless of shr-kinsoku-shorten.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111058
diff
changeset
|
283 (>= (setq count (1- count)) 0) |
938faaa83cf1
shr.el (shr-find-fill-point): Shorten line if the preceding char is kinsoku-eol regardless of shr-kinsoku-shorten.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111058
diff
changeset
|
284 (not (memq (preceding-char) (list ?\C-@ ?\n ? ))) |
111032
1ed05f12a0bc
shr.el: Improve kinsoku and table rendering.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111022
diff
changeset
|
285 (or (aref (char-category-set (preceding-char)) ?<) |
1ed05f12a0bc
shr.el: Improve kinsoku and table rendering.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111022
diff
changeset
|
286 (aref (char-category-set (following-char)) ?>))) |
1ed05f12a0bc
shr.el: Improve kinsoku and table rendering.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111022
diff
changeset
|
287 (backward-char 1)) |
111059
938faaa83cf1
shr.el (shr-find-fill-point): Shorten line if the preceding char is kinsoku-eol regardless of shr-kinsoku-shorten.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111058
diff
changeset
|
288 (while (and (>= (setq count (1- count)) 0) |
111269
3d7a1caabf14
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111245
diff
changeset
|
289 (aref (char-category-set (following-char)) ?>) |
3d7a1caabf14
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111245
diff
changeset
|
290 (aref fill-find-break-point-function-table |
3d7a1caabf14
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111245
diff
changeset
|
291 (following-char))) |
111032
1ed05f12a0bc
shr.el: Improve kinsoku and table rendering.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111022
diff
changeset
|
292 (forward-char 1))) |
111057
097fe1170a9a
shr.el (shr-find-fill-point): Don't leave blanks at the start of some lines.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111054
diff
changeset
|
293 (when (eq (following-char) ? ) |
097fe1170a9a
shr.el (shr-find-fill-point): Don't leave blanks at the start of some lines.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111054
diff
changeset
|
294 (forward-char 1)) |
111032
1ed05f12a0bc
shr.el: Improve kinsoku and table rendering.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111022
diff
changeset
|
295 t))))) |
110917
3243e7055d49
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110898
diff
changeset
|
296 |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
297 (defun shr-ensure-newline () |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
298 (unless (zerop (current-column)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
299 (insert "\n"))) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
300 |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
301 (defun shr-ensure-paragraph () |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
302 (unless (bobp) |
110898
069deed4cdec
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110873
diff
changeset
|
303 (if (<= (current-column) shr-indentation) |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
304 (unless (save-excursion |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
305 (forward-line -1) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
306 (looking-at " *$")) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
307 (insert "\n")) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
308 (if (save-excursion |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
309 (beginning-of-line) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
310 (looking-at " *$")) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
311 (insert "\n") |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
312 (insert "\n\n"))))) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
313 |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
314 (defun shr-indent () |
110898
069deed4cdec
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110873
diff
changeset
|
315 (when (> shr-indentation 0) |
069deed4cdec
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110873
diff
changeset
|
316 (insert (make-string shr-indentation ? )))) |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
317 |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
318 (defun shr-fontize-cont (cont &rest types) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
319 (let (shr-start) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
320 (shr-generic cont) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
321 (dolist (type types) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
322 (shr-add-font (or shr-start (point)) (point) type)))) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
323 |
111072
a7fee19797df
message.el (message-fix-before-sending): Change options when sending non-printable characters.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111067
diff
changeset
|
324 ;; Add an overlay in the region, but avoid putting the font properties |
a7fee19797df
message.el (message-fix-before-sending): Change options when sending non-printable characters.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111067
diff
changeset
|
325 ;; on blank text at the start of the line, and the newline at the end, |
a7fee19797df
message.el (message-fix-before-sending): Change options when sending non-printable characters.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111067
diff
changeset
|
326 ;; to avoid ugliness. |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
327 (defun shr-add-font (start end type) |
111072
a7fee19797df
message.el (message-fix-before-sending): Change options when sending non-printable characters.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111067
diff
changeset
|
328 (save-excursion |
a7fee19797df
message.el (message-fix-before-sending): Change options when sending non-printable characters.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111067
diff
changeset
|
329 (goto-char start) |
a7fee19797df
message.el (message-fix-before-sending): Change options when sending non-printable characters.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111067
diff
changeset
|
330 (while (< (point) end) |
a7fee19797df
message.el (message-fix-before-sending): Change options when sending non-printable characters.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111067
diff
changeset
|
331 (when (bolp) |
a7fee19797df
message.el (message-fix-before-sending): Change options when sending non-printable characters.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111067
diff
changeset
|
332 (skip-chars-forward " ")) |
a7fee19797df
message.el (message-fix-before-sending): Change options when sending non-printable characters.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111067
diff
changeset
|
333 (let ((overlay (make-overlay (point) (min (line-end-position) end)))) |
a7fee19797df
message.el (message-fix-before-sending): Change options when sending non-printable characters.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111067
diff
changeset
|
334 (overlay-put overlay 'face type)) |
a7fee19797df
message.el (message-fix-before-sending): Change options when sending non-printable characters.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111067
diff
changeset
|
335 (if (< (line-end-position) end) |
a7fee19797df
message.el (message-fix-before-sending): Change options when sending non-printable characters.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111067
diff
changeset
|
336 (forward-line 1) |
a7fee19797df
message.el (message-fix-before-sending): Change options when sending non-printable characters.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111067
diff
changeset
|
337 (goto-char end))))) |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
338 |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
339 (defun shr-browse-url () |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
340 "Browse the URL under point." |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
341 (interactive) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
342 (let ((url (get-text-property (point) 'shr-url))) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
343 (if (not url) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
344 (message "No link under point") |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
345 (browse-url url)))) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
346 |
111058
ea17726e9043
shr.el (shr-save-contents): New command and keystroke.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111057
diff
changeset
|
347 (defun shr-save-contents (directory) |
ea17726e9043
shr.el (shr-save-contents): New command and keystroke.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111057
diff
changeset
|
348 "Save the contents from URL in a file." |
ea17726e9043
shr.el (shr-save-contents): New command and keystroke.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111057
diff
changeset
|
349 (interactive "DSave contents of URL to directory: ") |
ea17726e9043
shr.el (shr-save-contents): New command and keystroke.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111057
diff
changeset
|
350 (let ((url (get-text-property (point) 'shr-url))) |
ea17726e9043
shr.el (shr-save-contents): New command and keystroke.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111057
diff
changeset
|
351 (if (not url) |
ea17726e9043
shr.el (shr-save-contents): New command and keystroke.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111057
diff
changeset
|
352 (message "No link under point") |
ea17726e9043
shr.el (shr-save-contents): New command and keystroke.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111057
diff
changeset
|
353 (url-retrieve (shr-encode-url url) |
ea17726e9043
shr.el (shr-save-contents): New command and keystroke.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111057
diff
changeset
|
354 'shr-store-contents (list url directory))))) |
ea17726e9043
shr.el (shr-save-contents): New command and keystroke.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111057
diff
changeset
|
355 |
ea17726e9043
shr.el (shr-save-contents): New command and keystroke.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111057
diff
changeset
|
356 (defun shr-store-contents (status url directory) |
ea17726e9043
shr.el (shr-save-contents): New command and keystroke.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111057
diff
changeset
|
357 (unless (plist-get status :error) |
ea17726e9043
shr.el (shr-save-contents): New command and keystroke.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111057
diff
changeset
|
358 (when (or (search-forward "\n\n" nil t) |
ea17726e9043
shr.el (shr-save-contents): New command and keystroke.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111057
diff
changeset
|
359 (search-forward "\r\n\r\n" nil t)) |
ea17726e9043
shr.el (shr-save-contents): New command and keystroke.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111057
diff
changeset
|
360 (write-region (point) (point-max) |
ea17726e9043
shr.el (shr-save-contents): New command and keystroke.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111057
diff
changeset
|
361 (expand-file-name (file-name-nondirectory url) |
ea17726e9043
shr.el (shr-save-contents): New command and keystroke.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111057
diff
changeset
|
362 directory))))) |
ea17726e9043
shr.el (shr-save-contents): New command and keystroke.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111057
diff
changeset
|
363 |
110708
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
364 (defun shr-image-fetched (status buffer start end) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
365 (when (and (buffer-name buffer) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
366 (not (plist-get status :error))) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
367 (url-store-in-cache (current-buffer)) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
368 (when (or (search-forward "\n\n" nil t) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
369 (search-forward "\r\n\r\n" nil t)) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
370 (let ((data (buffer-substring (point) (point-max)))) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
371 (with-current-buffer buffer |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
372 (let ((alt (buffer-substring start end)) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
373 (inhibit-read-only t)) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
374 (delete-region start end) |
111240
ffb890b32d37
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111218
diff
changeset
|
375 (goto-char start) |
ffb890b32d37
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111218
diff
changeset
|
376 (shr-put-image data alt)))))) |
110708
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
377 (kill-buffer (current-buffer))) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
378 |
111240
ffb890b32d37
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111218
diff
changeset
|
379 (defun shr-put-image (data alt) |
111218
b6601148b588
shr.el (shr-put-image): Use point even if only inserting text; save-excursion on alt text.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111195
diff
changeset
|
380 (if (display-graphic-p) |
b6601148b588
shr.el (shr-put-image): Use point even if only inserting text; save-excursion on alt text.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111195
diff
changeset
|
381 (let ((image (ignore-errors |
b6601148b588
shr.el (shr-put-image): Use point even if only inserting text; save-excursion on alt text.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111195
diff
changeset
|
382 (shr-rescale-image data)))) |
b6601148b588
shr.el (shr-put-image): Use point even if only inserting text; save-excursion on alt text.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111195
diff
changeset
|
383 (when image |
111240
ffb890b32d37
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111218
diff
changeset
|
384 (insert-image image (or alt "*")))) |
ffb890b32d37
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111218
diff
changeset
|
385 (insert alt))) |
110708
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
386 |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
387 (defun shr-rescale-image (data) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
388 (if (or (not (fboundp 'imagemagick-types)) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
389 (not (get-buffer-window (current-buffer)))) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
390 (create-image data nil t) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
391 (let* ((image (create-image data nil t)) |
110747
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
392 (size (image-size image t)) |
110708
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
393 (width (car size)) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
394 (height (cdr size)) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
395 (edges (window-inside-pixel-edges |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
396 (get-buffer-window (current-buffer)))) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
397 (window-width (truncate (* shr-max-image-proportion |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
398 (- (nth 2 edges) (nth 0 edges))))) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
399 (window-height (truncate (* shr-max-image-proportion |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
400 (- (nth 3 edges) (nth 1 edges))))) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
401 scaled-image) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
402 (when (> height window-height) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
403 (setq image (or (create-image data 'imagemagick t |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
404 :height window-height) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
405 image)) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
406 (setq size (image-size image t))) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
407 (when (> (car size) window-width) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
408 (setq image (or |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
409 (create-image data 'imagemagick t |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
410 :width window-width) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
411 image))) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
412 image))) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
413 |
111285 | 414 ;; url-cache-extract autoloads url-cache. |
415 (declare-function url-cache-create-filename "url-cache" (url)) | |
416 (autoload 'mm-disable-multibyte "mm-util") | |
417 | |
110708
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
418 (defun shr-get-image-data (url) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
419 "Get image data for URL. |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
420 Return a string with image data." |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
421 (with-temp-buffer |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
422 (mm-disable-multibyte) |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
423 (when (ignore-errors |
110957
627742e646c4
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110917
diff
changeset
|
424 (url-cache-extract (url-cache-create-filename (shr-encode-url url))) |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
425 t) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
426 (when (or (search-forward "\n\n" nil t) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
427 (search-forward "\r\n\r\n" nil t)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
428 (buffer-substring (point) (point-max)))))) |
110708
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
429 |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
430 (defun shr-heading (cont &rest types) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
431 (shr-ensure-paragraph) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
432 (apply #'shr-fontize-cont cont types) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
433 (shr-ensure-paragraph)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
434 |
111285 | 435 (autoload 'widget-convert-button "wid-edit") |
436 | |
111138
11259a64bfc0
gnus-sum.el (gnus-summary-select-article): Make sure we have the original article buffer live.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111129
diff
changeset
|
437 (defun shr-urlify (start url) |
11259a64bfc0
gnus-sum.el (gnus-summary-select-article): Make sure we have the original article buffer live.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111129
diff
changeset
|
438 (widget-convert-button |
11259a64bfc0
gnus-sum.el (gnus-summary-select-article): Make sure we have the original article buffer live.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111129
diff
changeset
|
439 'url-link start (point) |
11259a64bfc0
gnus-sum.el (gnus-summary-select-article): Make sure we have the original article buffer live.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111129
diff
changeset
|
440 :help-echo url |
11259a64bfc0
gnus-sum.el (gnus-summary-select-article): Make sure we have the original article buffer live.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111129
diff
changeset
|
441 :keymap shr-map |
11259a64bfc0
gnus-sum.el (gnus-summary-select-article): Make sure we have the original article buffer live.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111129
diff
changeset
|
442 url) |
11259a64bfc0
gnus-sum.el (gnus-summary-select-article): Make sure we have the original article buffer live.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111129
diff
changeset
|
443 (put-text-property start (point) 'shr-url url)) |
11259a64bfc0
gnus-sum.el (gnus-summary-select-article): Make sure we have the original article buffer live.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111129
diff
changeset
|
444 |
11259a64bfc0
gnus-sum.el (gnus-summary-select-article): Make sure we have the original article buffer live.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111129
diff
changeset
|
445 (defun shr-encode-url (url) |
11259a64bfc0
gnus-sum.el (gnus-summary-select-article): Make sure we have the original article buffer live.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111129
diff
changeset
|
446 "Encode URL." |
11259a64bfc0
gnus-sum.el (gnus-summary-select-article): Make sure we have the original article buffer live.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111129
diff
changeset
|
447 (browse-url-url-encode-chars url "[)$ ]")) |
11259a64bfc0
gnus-sum.el (gnus-summary-select-article): Make sure we have the original article buffer live.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111129
diff
changeset
|
448 |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
449 ;;; Tag-specific rendering rules. |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
450 |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
451 (defun shr-tag-p (cont) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
452 (shr-ensure-paragraph) |
110898
069deed4cdec
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110873
diff
changeset
|
453 (shr-indent) |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
454 (shr-generic cont) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
455 (shr-ensure-paragraph)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
456 |
111195
bad8d0e56e0f
shr.el (shr-tag-div): Added.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111138
diff
changeset
|
457 (defun shr-tag-div (cont) |
bad8d0e56e0f
shr.el (shr-tag-div): Added.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111138
diff
changeset
|
458 (shr-ensure-newline) |
bad8d0e56e0f
shr.el (shr-tag-div): Added.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111138
diff
changeset
|
459 (shr-indent) |
bad8d0e56e0f
shr.el (shr-tag-div): Added.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111138
diff
changeset
|
460 (shr-generic cont) |
bad8d0e56e0f
shr.el (shr-tag-div): Added.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111138
diff
changeset
|
461 (shr-ensure-newline)) |
bad8d0e56e0f
shr.el (shr-tag-div): Added.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111138
diff
changeset
|
462 |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
463 (defun shr-tag-b (cont) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
464 (shr-fontize-cont cont 'bold)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
465 |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
466 (defun shr-tag-i (cont) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
467 (shr-fontize-cont cont 'italic)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
468 |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
469 (defun shr-tag-em (cont) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
470 (shr-fontize-cont cont 'bold)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
471 |
111129
2d713b285a70
gnus-group.el (gnus-group-completing-read): Remove all newlines from group names. They mess up the group buffer badly.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111096
diff
changeset
|
472 (defun shr-tag-strong (cont) |
2d713b285a70
gnus-group.el (gnus-group-completing-read): Remove all newlines from group names. They mess up the group buffer badly.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111096
diff
changeset
|
473 (shr-fontize-cont cont 'bold)) |
2d713b285a70
gnus-group.el (gnus-group-completing-read): Remove all newlines from group names. They mess up the group buffer badly.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111096
diff
changeset
|
474 |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
475 (defun shr-tag-u (cont) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
476 (shr-fontize-cont cont 'underline)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
477 |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
478 (defun shr-tag-s (cont) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
479 (shr-fontize-cont cont 'strike-through)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
480 |
111054
779cd575396a
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111033
diff
changeset
|
481 (defun shr-parse-style (style) |
779cd575396a
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111033
diff
changeset
|
482 (when style |
779cd575396a
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111033
diff
changeset
|
483 (let ((plist nil)) |
779cd575396a
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111033
diff
changeset
|
484 (dolist (elem (split-string style ";")) |
779cd575396a
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111033
diff
changeset
|
485 (when elem |
779cd575396a
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111033
diff
changeset
|
486 (setq elem (split-string elem ":")) |
779cd575396a
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111033
diff
changeset
|
487 (when (and (car elem) |
779cd575396a
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111033
diff
changeset
|
488 (cadr elem)) |
779cd575396a
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111033
diff
changeset
|
489 (let ((name (replace-regexp-in-string "^ +\\| +$" "" (car elem))) |
779cd575396a
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111033
diff
changeset
|
490 (value (replace-regexp-in-string "^ +\\| +$" "" (cadr elem)))) |
779cd575396a
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111033
diff
changeset
|
491 (push (cons (intern name obarray) |
779cd575396a
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111033
diff
changeset
|
492 value) |
779cd575396a
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111033
diff
changeset
|
493 plist))))) |
779cd575396a
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111033
diff
changeset
|
494 plist))) |
779cd575396a
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111033
diff
changeset
|
495 |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
496 (defun shr-tag-a (cont) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
497 (let ((url (cdr (assq :href cont))) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
498 (start (point)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
499 shr-start) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
500 (shr-generic cont) |
111138
11259a64bfc0
gnus-sum.el (gnus-summary-select-article): Make sure we have the original article buffer live.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111129
diff
changeset
|
501 (shr-urlify (or shr-start start) url))) |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
502 |
111138
11259a64bfc0
gnus-sum.el (gnus-summary-select-article): Make sure we have the original article buffer live.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111129
diff
changeset
|
503 (defun shr-tag-object (cont) |
111240
ffb890b32d37
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111218
diff
changeset
|
504 (let ((start (point)) |
ffb890b32d37
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111218
diff
changeset
|
505 url) |
ffb890b32d37
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111218
diff
changeset
|
506 (dolist (elem cont) |
ffb890b32d37
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111218
diff
changeset
|
507 (when (eq (car elem) 'embed) |
ffb890b32d37
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111218
diff
changeset
|
508 (setq url (or url (cdr (assq :src (cdr elem)))))) |
ffb890b32d37
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111218
diff
changeset
|
509 (when (and (eq (car elem) 'param) |
ffb890b32d37
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111218
diff
changeset
|
510 (equal (cdr (assq :name (cdr elem))) "movie")) |
ffb890b32d37
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111218
diff
changeset
|
511 (setq url (or url (cdr (assq :value (cdr elem))))))) |
111138
11259a64bfc0
gnus-sum.el (gnus-summary-select-article): Make sure we have the original article buffer live.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111129
diff
changeset
|
512 (when url |
11259a64bfc0
gnus-sum.el (gnus-summary-select-article): Make sure we have the original article buffer live.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111129
diff
changeset
|
513 (shr-insert " [multimedia] ") |
111240
ffb890b32d37
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111218
diff
changeset
|
514 (shr-urlify start url)) |
ffb890b32d37
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111218
diff
changeset
|
515 (shr-generic cont))) |
110957
627742e646c4
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110917
diff
changeset
|
516 |
111240
ffb890b32d37
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111218
diff
changeset
|
517 (defun shr-tag-video (cont) |
ffb890b32d37
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111218
diff
changeset
|
518 (let ((image (cdr (assq :poster cont))) |
ffb890b32d37
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111218
diff
changeset
|
519 (url (cdr (assq :src cont))) |
ffb890b32d37
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111218
diff
changeset
|
520 (start (point))) |
ffb890b32d37
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111218
diff
changeset
|
521 (shr-tag-img nil image) |
ffb890b32d37
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111218
diff
changeset
|
522 (shr-urlify start url))) |
ffb890b32d37
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111218
diff
changeset
|
523 |
ffb890b32d37
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111218
diff
changeset
|
524 (defun shr-tag-img (cont &optional url) |
ffb890b32d37
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111218
diff
changeset
|
525 (when (or url |
ffb890b32d37
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111218
diff
changeset
|
526 (and cont |
ffb890b32d37
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111218
diff
changeset
|
527 (cdr (assq :src cont)))) |
111005
e172bc1db402
shr.el (shr-tag-img): Ignore images with no data.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111002
diff
changeset
|
528 (when (and (> (current-column) 0) |
e172bc1db402
shr.el (shr-tag-img): Ignore images with no data.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111002
diff
changeset
|
529 (not (eq shr-state 'image))) |
e172bc1db402
shr.el (shr-tag-img): Ignore images with no data.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111002
diff
changeset
|
530 (insert "\n")) |
e172bc1db402
shr.el (shr-tag-img): Ignore images with no data.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111002
diff
changeset
|
531 (let ((alt (cdr (assq :alt cont))) |
111240
ffb890b32d37
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111218
diff
changeset
|
532 (url (or url (cdr (assq :src cont))))) |
111005
e172bc1db402
shr.el (shr-tag-img): Ignore images with no data.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111002
diff
changeset
|
533 (let ((start (point-marker))) |
e172bc1db402
shr.el (shr-tag-img): Ignore images with no data.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111002
diff
changeset
|
534 (when (zerop (length alt)) |
111245
dd1304e89176
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111240
diff
changeset
|
535 (setq alt "*")) |
111005
e172bc1db402
shr.el (shr-tag-img): Ignore images with no data.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111002
diff
changeset
|
536 (cond |
111240
ffb890b32d37
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111218
diff
changeset
|
537 ((or (member (cdr (assq :height cont)) '("0" "1")) |
ffb890b32d37
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111218
diff
changeset
|
538 (member (cdr (assq :width cont)) '("0" "1"))) |
ffb890b32d37
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111218
diff
changeset
|
539 ;; Ignore zero-sized or single-pixel images. |
ffb890b32d37
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111218
diff
changeset
|
540 ) |
111005
e172bc1db402
shr.el (shr-tag-img): Ignore images with no data.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111002
diff
changeset
|
541 ((and (not shr-inhibit-images) |
e172bc1db402
shr.el (shr-tag-img): Ignore images with no data.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111002
diff
changeset
|
542 (string-match "\\`cid:" url)) |
e172bc1db402
shr.el (shr-tag-img): Ignore images with no data.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111002
diff
changeset
|
543 (let ((url (substring url (match-end 0))) |
e172bc1db402
shr.el (shr-tag-img): Ignore images with no data.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111002
diff
changeset
|
544 image) |
e172bc1db402
shr.el (shr-tag-img): Ignore images with no data.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111002
diff
changeset
|
545 (if (or (not shr-content-function) |
e172bc1db402
shr.el (shr-tag-img): Ignore images with no data.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111002
diff
changeset
|
546 (not (setq image (funcall shr-content-function url)))) |
e172bc1db402
shr.el (shr-tag-img): Ignore images with no data.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111002
diff
changeset
|
547 (insert alt) |
111240
ffb890b32d37
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111218
diff
changeset
|
548 (shr-put-image image alt)))) |
111005
e172bc1db402
shr.el (shr-tag-img): Ignore images with no data.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111002
diff
changeset
|
549 ((or shr-inhibit-images |
e172bc1db402
shr.el (shr-tag-img): Ignore images with no data.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111002
diff
changeset
|
550 (and shr-blocked-images |
e172bc1db402
shr.el (shr-tag-img): Ignore images with no data.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111002
diff
changeset
|
551 (string-match shr-blocked-images url))) |
e172bc1db402
shr.el (shr-tag-img): Ignore images with no data.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111002
diff
changeset
|
552 (setq shr-start (point)) |
e172bc1db402
shr.el (shr-tag-img): Ignore images with no data.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111002
diff
changeset
|
553 (let ((shr-state 'space)) |
e172bc1db402
shr.el (shr-tag-img): Ignore images with no data.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111002
diff
changeset
|
554 (if (> (length alt) 8) |
e172bc1db402
shr.el (shr-tag-img): Ignore images with no data.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111002
diff
changeset
|
555 (shr-insert (substring alt 0 8)) |
e172bc1db402
shr.el (shr-tag-img): Ignore images with no data.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111002
diff
changeset
|
556 (shr-insert alt)))) |
e172bc1db402
shr.el (shr-tag-img): Ignore images with no data.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111002
diff
changeset
|
557 ((url-is-cached (shr-encode-url url)) |
111240
ffb890b32d37
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111218
diff
changeset
|
558 (shr-put-image (shr-get-image-data url) alt)) |
111005
e172bc1db402
shr.el (shr-tag-img): Ignore images with no data.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111002
diff
changeset
|
559 (t |
e172bc1db402
shr.el (shr-tag-img): Ignore images with no data.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111002
diff
changeset
|
560 (insert alt) |
e172bc1db402
shr.el (shr-tag-img): Ignore images with no data.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111002
diff
changeset
|
561 (ignore-errors |
e172bc1db402
shr.el (shr-tag-img): Ignore images with no data.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111002
diff
changeset
|
562 (url-retrieve (shr-encode-url url) 'shr-image-fetched |
e172bc1db402
shr.el (shr-tag-img): Ignore images with no data.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111002
diff
changeset
|
563 (list (current-buffer) start (point-marker)) |
e172bc1db402
shr.el (shr-tag-img): Ignore images with no data.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111002
diff
changeset
|
564 t)))) |
e172bc1db402
shr.el (shr-tag-img): Ignore images with no data.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111002
diff
changeset
|
565 (put-text-property start (point) 'keymap shr-map) |
e172bc1db402
shr.el (shr-tag-img): Ignore images with no data.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111002
diff
changeset
|
566 (put-text-property start (point) 'shr-alt alt) |
e172bc1db402
shr.el (shr-tag-img): Ignore images with no data.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111002
diff
changeset
|
567 (put-text-property start (point) 'shr-image url) |
111240
ffb890b32d37
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111218
diff
changeset
|
568 (put-text-property start (point) 'help-echo alt) |
111005
e172bc1db402
shr.el (shr-tag-img): Ignore images with no data.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111002
diff
changeset
|
569 (setq shr-state 'image))))) |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
570 |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
571 (defun shr-tag-pre (cont) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
572 (let ((shr-folding-mode 'none)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
573 (shr-ensure-newline) |
110898
069deed4cdec
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110873
diff
changeset
|
574 (shr-indent) |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
575 (shr-generic cont) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
576 (shr-ensure-newline))) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
577 |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
578 (defun shr-tag-blockquote (cont) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
579 (shr-ensure-paragraph) |
110898
069deed4cdec
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110873
diff
changeset
|
580 (shr-indent) |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
581 (let ((shr-indentation (+ shr-indentation 4))) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
582 (shr-generic cont)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
583 (shr-ensure-paragraph)) |
110747
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
584 |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
585 (defun shr-tag-ul (cont) |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
586 (shr-ensure-paragraph) |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
587 (let ((shr-list-mode 'ul)) |
110810
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
588 (shr-generic cont)) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
589 (shr-ensure-paragraph)) |
110747
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
590 |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
591 (defun shr-tag-ol (cont) |
110810
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
592 (shr-ensure-paragraph) |
110747
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
593 (let ((shr-list-mode 1)) |
110810
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
594 (shr-generic cont)) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
595 (shr-ensure-paragraph)) |
110747
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
596 |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
597 (defun shr-tag-li (cont) |
110898
069deed4cdec
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110873
diff
changeset
|
598 (shr-ensure-paragraph) |
069deed4cdec
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110873
diff
changeset
|
599 (shr-indent) |
110757
d3001fd75795
shr.el (shr-tag-li): Get <li> indentation right.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110756
diff
changeset
|
600 (let* ((bullet |
d3001fd75795
shr.el (shr-tag-li): Get <li> indentation right.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110756
diff
changeset
|
601 (if (numberp shr-list-mode) |
d3001fd75795
shr.el (shr-tag-li): Get <li> indentation right.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110756
diff
changeset
|
602 (prog1 |
d3001fd75795
shr.el (shr-tag-li): Get <li> indentation right.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110756
diff
changeset
|
603 (format "%d " shr-list-mode) |
d3001fd75795
shr.el (shr-tag-li): Get <li> indentation right.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110756
diff
changeset
|
604 (setq shr-list-mode (1+ shr-list-mode))) |
d3001fd75795
shr.el (shr-tag-li): Get <li> indentation right.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110756
diff
changeset
|
605 "* ")) |
d3001fd75795
shr.el (shr-tag-li): Get <li> indentation right.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110756
diff
changeset
|
606 (shr-indentation (+ shr-indentation (length bullet)))) |
d3001fd75795
shr.el (shr-tag-li): Get <li> indentation right.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110756
diff
changeset
|
607 (insert bullet) |
d3001fd75795
shr.el (shr-tag-li): Get <li> indentation right.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110756
diff
changeset
|
608 (shr-generic cont))) |
110747
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
609 |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
610 (defun shr-tag-br (cont) |
110756
9070b77b4a28
shr.el (shr-insert): Tweak line breaking.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110755
diff
changeset
|
611 (unless (bobp) |
110898
069deed4cdec
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110873
diff
changeset
|
612 (insert "\n") |
069deed4cdec
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110873
diff
changeset
|
613 (shr-indent)) |
110747
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
614 (shr-generic cont)) |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
615 |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
616 (defun shr-tag-h1 (cont) |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
617 (shr-heading cont 'bold 'underline)) |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
618 |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
619 (defun shr-tag-h2 (cont) |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
620 (shr-heading cont 'bold)) |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
621 |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
622 (defun shr-tag-h3 (cont) |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
623 (shr-heading cont 'italic)) |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
624 |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
625 (defun shr-tag-h4 (cont) |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
626 (shr-heading cont)) |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
627 |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
628 (defun shr-tag-h5 (cont) |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
629 (shr-heading cont)) |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
630 |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
631 (defun shr-tag-h6 (cont) |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
632 (shr-heading cont)) |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
633 |
110810
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
634 (defun shr-tag-hr (cont) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
635 (shr-ensure-newline) |
110917
3243e7055d49
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110898
diff
changeset
|
636 (insert (make-string shr-width shr-hr-line) "\n")) |
110810
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
637 |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
638 ;;; Table rendering algorithm. |
110747
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
639 |
110778
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
640 ;; Table rendering is the only complicated thing here. We do this by |
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
641 ;; first counting how many TDs there are in each TR, and registering |
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
642 ;; how wide they think they should be ("width=45%", etc). Then we |
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
643 ;; render each TD separately (this is done in temporary buffers, so |
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
644 ;; that we can use all the rendering machinery as if we were in the |
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
645 ;; main buffer). Now we know how much space each TD really takes, so |
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
646 ;; we then render everything again with the new widths, and finally |
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
647 ;; insert all these boxes into the main buffer. |
111063
4430b518c7c5
shr.el: (shr-tag-table): Support caption, thead, and tfoot.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111059
diff
changeset
|
648 (defun shr-tag-table-1 (cont) |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
649 (setq cont (or (cdr (assq 'tbody cont)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
650 cont)) |
110777
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
651 (let* ((shr-inhibit-images t) |
111240
ffb890b32d37
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111218
diff
changeset
|
652 (shr-table-depth (1+ shr-table-depth)) |
111032
1ed05f12a0bc
shr.el: Improve kinsoku and table rendering.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111022
diff
changeset
|
653 (shr-kinsoku-shorten t) |
110778
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
654 ;; Find all suggested widths. |
110777
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
655 (columns (shr-column-specs cont)) |
110778
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
656 ;; Compute how many characters wide each TD should be. |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
657 (suggested-widths (shr-pro-rate-columns columns)) |
110778
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
658 ;; Do a "test rendering" to see how big each TD is (this can |
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
659 ;; be smaller (if there's little text) or bigger (if there's |
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
660 ;; unbreakable text). |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
661 (sketch (shr-make-table cont suggested-widths)) |
110804
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
662 (sketch-widths (shr-table-widths sketch suggested-widths))) |
110999
9330a5183ae6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110996
diff
changeset
|
663 ;; This probably won't work very well. |
111032
1ed05f12a0bc
shr.el: Improve kinsoku and table rendering.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111022
diff
changeset
|
664 (when (> (+ (loop for width across sketch-widths |
1ed05f12a0bc
shr.el: Improve kinsoku and table rendering.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111022
diff
changeset
|
665 summing (1+ width)) |
1ed05f12a0bc
shr.el: Improve kinsoku and table rendering.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111022
diff
changeset
|
666 shr-indentation 1) |
110999
9330a5183ae6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110996
diff
changeset
|
667 (frame-width)) |
9330a5183ae6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110996
diff
changeset
|
668 (setq truncate-lines t)) |
110778
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
669 ;; Then render the table again with these new "hard" widths. |
110777
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
670 (shr-insert-table (shr-make-table cont sketch-widths t) sketch-widths)) |
110778
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
671 ;; Finally, insert all the images after the table. The Emacs buffer |
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
672 ;; model isn't strong enough to allow us to put the images actually |
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
673 ;; into the tables. |
111240
ffb890b32d37
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111218
diff
changeset
|
674 (when (zerop shr-table-depth) |
ffb890b32d37
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111218
diff
changeset
|
675 (dolist (elem (shr-find-elements cont 'img)) |
ffb890b32d37
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111218
diff
changeset
|
676 (shr-tag-img (cdr elem))))) |
110777
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
677 |
111063
4430b518c7c5
shr.el: (shr-tag-table): Support caption, thead, and tfoot.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111059
diff
changeset
|
678 (defun shr-tag-table (cont) |
4430b518c7c5
shr.el: (shr-tag-table): Support caption, thead, and tfoot.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111059
diff
changeset
|
679 (shr-ensure-paragraph) |
4430b518c7c5
shr.el: (shr-tag-table): Support caption, thead, and tfoot.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111059
diff
changeset
|
680 (let* ((caption (cdr (assq 'caption cont))) |
4430b518c7c5
shr.el: (shr-tag-table): Support caption, thead, and tfoot.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111059
diff
changeset
|
681 (header (cdr (assq 'thead cont))) |
4430b518c7c5
shr.el: (shr-tag-table): Support caption, thead, and tfoot.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111059
diff
changeset
|
682 (body (or (cdr (assq 'tbody cont)) cont)) |
4430b518c7c5
shr.el: (shr-tag-table): Support caption, thead, and tfoot.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111059
diff
changeset
|
683 (footer (cdr (assq 'tfoot cont))) |
4430b518c7c5
shr.el: (shr-tag-table): Support caption, thead, and tfoot.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111059
diff
changeset
|
684 (nheader (if header (shr-max-columns header))) |
4430b518c7c5
shr.el: (shr-tag-table): Support caption, thead, and tfoot.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111059
diff
changeset
|
685 (nbody (if body (shr-max-columns body))) |
4430b518c7c5
shr.el: (shr-tag-table): Support caption, thead, and tfoot.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111059
diff
changeset
|
686 (nfooter (if footer (shr-max-columns footer)))) |
4430b518c7c5
shr.el: (shr-tag-table): Support caption, thead, and tfoot.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111059
diff
changeset
|
687 (shr-tag-table-1 |
111078
647c0a15da32
shr.el (shr-tag-table): Simplify.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111072
diff
changeset
|
688 (nconc |
647c0a15da32
shr.el (shr-tag-table): Simplify.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111072
diff
changeset
|
689 (if caption `((tr (td ,@caption)))) |
647c0a15da32
shr.el (shr-tag-table): Simplify.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111072
diff
changeset
|
690 (if header |
647c0a15da32
shr.el (shr-tag-table): Simplify.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111072
diff
changeset
|
691 (if footer |
647c0a15da32
shr.el (shr-tag-table): Simplify.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111072
diff
changeset
|
692 ;; hader + body + footer |
647c0a15da32
shr.el (shr-tag-table): Simplify.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111072
diff
changeset
|
693 (if (= nheader nbody) |
647c0a15da32
shr.el (shr-tag-table): Simplify.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111072
diff
changeset
|
694 (if (= nbody nfooter) |
647c0a15da32
shr.el (shr-tag-table): Simplify.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111072
diff
changeset
|
695 `((tr (td (table (tbody ,@header ,@body ,@footer))))) |
647c0a15da32
shr.el (shr-tag-table): Simplify.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111072
diff
changeset
|
696 (nconc `((tr (td (table (tbody ,@header ,@body))))) |
647c0a15da32
shr.el (shr-tag-table): Simplify.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111072
diff
changeset
|
697 (if (= nfooter 1) |
647c0a15da32
shr.el (shr-tag-table): Simplify.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111072
diff
changeset
|
698 footer |
647c0a15da32
shr.el (shr-tag-table): Simplify.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111072
diff
changeset
|
699 `((tr (td (table (tbody ,@footer)))))))) |
647c0a15da32
shr.el (shr-tag-table): Simplify.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111072
diff
changeset
|
700 (nconc `((tr (td (table (tbody ,@header))))) |
647c0a15da32
shr.el (shr-tag-table): Simplify.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111072
diff
changeset
|
701 (if (= nbody nfooter) |
647c0a15da32
shr.el (shr-tag-table): Simplify.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111072
diff
changeset
|
702 `((tr (td (table (tbody ,@body ,@footer))))) |
647c0a15da32
shr.el (shr-tag-table): Simplify.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111072
diff
changeset
|
703 (nconc `((tr (td (table (tbody ,@body))))) |
647c0a15da32
shr.el (shr-tag-table): Simplify.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111072
diff
changeset
|
704 (if (= nfooter 1) |
647c0a15da32
shr.el (shr-tag-table): Simplify.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111072
diff
changeset
|
705 footer |
647c0a15da32
shr.el (shr-tag-table): Simplify.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111072
diff
changeset
|
706 `((tr (td (table (tbody ,@footer)))))))))) |
647c0a15da32
shr.el (shr-tag-table): Simplify.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111072
diff
changeset
|
707 ;; header + body |
647c0a15da32
shr.el (shr-tag-table): Simplify.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111072
diff
changeset
|
708 (if (= nheader nbody) |
647c0a15da32
shr.el (shr-tag-table): Simplify.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111072
diff
changeset
|
709 `((tr (td (table (tbody ,@header ,@body))))) |
647c0a15da32
shr.el (shr-tag-table): Simplify.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111072
diff
changeset
|
710 (if (= nheader 1) |
647c0a15da32
shr.el (shr-tag-table): Simplify.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111072
diff
changeset
|
711 `(,@header (tr (td (table (tbody ,@body))))) |
647c0a15da32
shr.el (shr-tag-table): Simplify.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111072
diff
changeset
|
712 `((tr (td (table (tbody ,@header)))) |
647c0a15da32
shr.el (shr-tag-table): Simplify.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111072
diff
changeset
|
713 (tr (td (table (tbody ,@body)))))))) |
647c0a15da32
shr.el (shr-tag-table): Simplify.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111072
diff
changeset
|
714 (if footer |
647c0a15da32
shr.el (shr-tag-table): Simplify.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111072
diff
changeset
|
715 ;; body + footer |
647c0a15da32
shr.el (shr-tag-table): Simplify.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111072
diff
changeset
|
716 (if (= nbody nfooter) |
647c0a15da32
shr.el (shr-tag-table): Simplify.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111072
diff
changeset
|
717 `((tr (td (table (tbody ,@body ,@footer))))) |
647c0a15da32
shr.el (shr-tag-table): Simplify.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111072
diff
changeset
|
718 (nconc `((tr (td (table (tbody ,@body))))) |
111067
e36c65ac23bf
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111066
diff
changeset
|
719 (if (= nfooter 1) |
111078
647c0a15da32
shr.el (shr-tag-table): Simplify.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111072
diff
changeset
|
720 footer |
647c0a15da32
shr.el (shr-tag-table): Simplify.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111072
diff
changeset
|
721 `((tr (td (table (tbody ,@footer)))))))) |
647c0a15da32
shr.el (shr-tag-table): Simplify.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111072
diff
changeset
|
722 (if caption |
647c0a15da32
shr.el (shr-tag-table): Simplify.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111072
diff
changeset
|
723 `((tr (td (table (tbody ,@body))))) |
647c0a15da32
shr.el (shr-tag-table): Simplify.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111072
diff
changeset
|
724 body))))))) |
111063
4430b518c7c5
shr.el: (shr-tag-table): Support caption, thead, and tfoot.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111059
diff
changeset
|
725 |
110777
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
726 (defun shr-find-elements (cont type) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
727 (let (result) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
728 (dolist (elem cont) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
729 (cond ((eq (car elem) type) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
730 (push elem result)) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
731 ((consp (cdr elem)) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
732 (setq result (nconc (shr-find-elements (cdr elem) type) result))))) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
733 (nreverse result))) |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
734 |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
735 (defun shr-insert-table (table widths) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
736 (shr-insert-table-ruler widths) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
737 (dolist (row table) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
738 (let ((start (point)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
739 (height (let ((max 0)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
740 (dolist (column row) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
741 (setq max (max max (cadr column)))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
742 max))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
743 (dotimes (i height) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
744 (shr-indent) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
745 (insert "|\n")) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
746 (dolist (column row) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
747 (goto-char start) |
110804
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
748 (let ((lines (nth 2 column)) |
110777
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
749 (overlay-lines (nth 3 column)) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
750 overlay overlay-line) |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
751 (dolist (line lines) |
110777
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
752 (setq overlay-line (pop overlay-lines)) |
110810
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
753 (end-of-line) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
754 (insert line "|") |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
755 (dolist (overlay overlay-line) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
756 (let ((o (make-overlay (- (point) (nth 0 overlay) 1) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
757 (- (point) (nth 1 overlay) 1))) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
758 (properties (nth 2 overlay))) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
759 (while properties |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
760 (overlay-put o (pop properties) (pop properties))))) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
761 (forward-line 1)) |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
762 ;; Add blank lines at padding at the bottom of the TD, |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
763 ;; possibly. |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
764 (dotimes (i (- height (length lines))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
765 (end-of-line) |
111032
1ed05f12a0bc
shr.el: Improve kinsoku and table rendering.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111022
diff
changeset
|
766 (insert (make-string (string-width (car lines)) ? ) "|") |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
767 (forward-line 1))))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
768 (shr-insert-table-ruler widths))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
769 |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
770 (defun shr-insert-table-ruler (widths) |
111032
1ed05f12a0bc
shr.el: Improve kinsoku and table rendering.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111022
diff
changeset
|
771 (when (and (bolp) |
1ed05f12a0bc
shr.el: Improve kinsoku and table rendering.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111022
diff
changeset
|
772 (> shr-indentation 0)) |
1ed05f12a0bc
shr.el: Improve kinsoku and table rendering.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
111022
diff
changeset
|
773 (shr-indent)) |
110873
d98a67277730
shr,el: Allow shr table char to be customized.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110859
diff
changeset
|
774 (insert shr-table-corner) |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
775 (dotimes (i (length widths)) |
110873
d98a67277730
shr,el: Allow shr table char to be customized.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110859
diff
changeset
|
776 (insert (make-string (aref widths i) shr-table-line) shr-table-corner)) |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
777 (insert "\n")) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
778 |
110804
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
779 (defun shr-table-widths (table suggested-widths) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
780 (let* ((length (length suggested-widths)) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
781 (widths (make-vector length 0)) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
782 (natural-widths (make-vector length 0))) |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
783 (dolist (row table) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
784 (let ((i 0)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
785 (dolist (column row) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
786 (aset widths i (max (aref widths i) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
787 (car column))) |
110804
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
788 (aset natural-widths i (max (aref natural-widths i) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
789 (cadr column))) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
790 (setq i (1+ i))))) |
110812
3d3d15223058
shr.el (shr-table-widths): Don't use cl function `reduce'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110810
diff
changeset
|
791 (let ((extra (- (apply '+ (append suggested-widths nil)) |
3d3d15223058
shr.el (shr-table-widths): Don't use cl function `reduce'.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110810
diff
changeset
|
792 (apply '+ (append widths nil)))) |
110804
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
793 (expanded-columns 0)) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
794 (when (> extra 0) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
795 (dotimes (i length) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
796 ;; If the natural width is wider than the rendered width, we |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
797 ;; want to allow the column to expand. |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
798 (when (> (aref natural-widths i) (aref widths i)) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
799 (setq expanded-columns (1+ expanded-columns)))) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
800 (dotimes (i length) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
801 (when (> (aref natural-widths i) (aref widths i)) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
802 (aset widths i (min |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
803 (1+ (aref natural-widths i)) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
804 (+ (/ extra expanded-columns) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
805 (aref widths i)))))))) |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
806 widths)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
807 |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
808 (defun shr-make-table (cont widths &optional fill) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
809 (let ((trs nil)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
810 (dolist (row cont) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
811 (when (eq (car row) 'tr) |
110778
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
812 (let ((tds nil) |
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
813 (columns (cdr row)) |
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
814 (i 0) |
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
815 column) |
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
816 (while (< i (length widths)) |
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
817 (setq column (pop columns)) |
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
818 (when (or (memq (car column) '(td th)) |
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
819 (null column)) |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
820 (push (shr-render-td (cdr column) (aref widths i) fill) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
821 tds) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
822 (setq i (1+ i)))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
823 (push (nreverse tds) trs)))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
824 (nreverse trs))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
825 |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
826 (defun shr-render-td (cont width fill) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
827 (with-temp-buffer |
110810
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
828 (let ((cache (cdr (assoc (cons width cont) shr-content-cache)))) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
829 (if cache |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
830 (insert cache) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
831 (let ((shr-width width) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
832 (shr-indentation 0)) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
833 (shr-generic cont)) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
834 (delete-region |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
835 (point) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
836 (+ (point) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
837 (skip-chars-backward " \t\n"))) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
838 (push (cons (cons width cont) (buffer-string)) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
839 shr-content-cache))) |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
840 (goto-char (point-min)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
841 (let ((max 0)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
842 (while (not (eobp)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
843 (end-of-line) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
844 (setq max (max max (current-column))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
845 (forward-line 1)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
846 (when fill |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
847 (goto-char (point-min)) |
110778
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
848 ;; If the buffer is totally empty, then put a single blank |
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
849 ;; line here. |
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
850 (if (zerop (buffer-size)) |
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
851 (insert (make-string width ? )) |
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
852 ;; Otherwise, fill the buffer. |
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
853 (while (not (eobp)) |
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
854 (end-of-line) |
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
855 (when (> (- width (current-column)) 0) |
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
856 (insert (make-string (- width (current-column)) ? ))) |
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
857 (forward-line 1)))) |
110804
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
858 (if fill |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
859 (list max |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
860 (count-lines (point-min) (point-max)) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
861 (split-string (buffer-string) "\n") |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
862 (shr-collect-overlays)) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
863 (list max |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
864 (shr-natural-width)))))) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
865 |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
866 (defun shr-natural-width () |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
867 (goto-char (point-min)) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
868 (let ((current 0) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
869 (max 0)) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
870 (while (not (eobp)) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
871 (end-of-line) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
872 (setq current (+ current (current-column))) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
873 (unless (get-text-property (point) 'shr-break) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
874 (setq max (max max current) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
875 current 0)) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
876 (forward-line 1)) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
877 max)) |
110777
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
878 |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
879 (defun shr-collect-overlays () |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
880 (save-excursion |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
881 (goto-char (point-min)) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
882 (let ((overlays nil)) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
883 (while (not (eobp)) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
884 (push (shr-overlays-in-region (point) (line-end-position)) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
885 overlays) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
886 (forward-line 1)) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
887 (nreverse overlays)))) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
888 |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
889 (defun shr-overlays-in-region (start end) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
890 (let (result) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
891 (dolist (overlay (overlays-in start end)) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
892 (push (list (if (> start (overlay-start overlay)) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
893 (- end start) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
894 (- end (overlay-start overlay))) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
895 (if (< end (overlay-end overlay)) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
896 0 |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
897 (- end (overlay-end overlay))) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
898 (overlay-properties overlay)) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
899 result)) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
900 (nreverse result))) |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
901 |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
902 (defun shr-pro-rate-columns (columns) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
903 (let ((total-percentage 0) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
904 (widths (make-vector (length columns) 0))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
905 (dotimes (i (length columns)) |
110804
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
906 (setq total-percentage (+ total-percentage (aref columns i)))) |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
907 (setq total-percentage (/ 1.0 total-percentage)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
908 (dotimes (i (length columns)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
909 (aset widths i (max (truncate (* (aref columns i) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
910 total-percentage |
110804
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
911 (- shr-width (1+ (length columns))))) |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
912 10))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
913 widths)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
914 |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
915 ;; Return a summary of the number and shape of the TDs in the table. |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
916 (defun shr-column-specs (cont) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
917 (let ((columns (make-vector (shr-max-columns cont) 1))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
918 (dolist (row cont) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
919 (when (eq (car row) 'tr) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
920 (let ((i 0)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
921 (dolist (column (cdr row)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
922 (when (memq (car column) '(td th)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
923 (let ((width (cdr (assq :width (cdr column))))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
924 (when (and width |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
925 (string-match "\\([0-9]+\\)%" width)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
926 (aset columns i |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
927 (/ (string-to-number (match-string 1 width)) |
110777
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
928 100.0)))) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
929 (setq i (1+ i))))))) |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
930 columns)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
931 |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
932 (defun shr-count (cont elem) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
933 (let ((i 0)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
934 (dolist (sub cont) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
935 (when (eq (car sub) elem) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
936 (setq i (1+ i)))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
937 i)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
938 |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
939 (defun shr-max-columns (cont) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
940 (let ((max 0)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
941 (dolist (row cont) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
942 (when (eq (car row) 'tr) |
110777
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
943 (setq max (max max (+ (shr-count (cdr row) 'td) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
944 (shr-count (cdr row) 'th)))))) |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
945 max)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
946 |
110704
016990bf37ad
lisp/gnus/shr.el (shr): Fix typo in provide call.
Juanma Barranquero <lekktu@gmail.com>
parents:
110698
diff
changeset
|
947 (provide 'shr) |
110698
74bad2d7bddd
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
948 |
74bad2d7bddd
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
949 ;;; shr.el ends here |