Mercurial > emacs
annotate lisp/gnus/shr.el @ 110966:0272ba632fc2
shr: make shr-width a defcustom, use it in shr-tag-img.
author | Katsumi Yamaoka <yamaoka@jpl.org> |
---|---|
date | Wed, 13 Oct 2010 11:55:48 +0000 |
parents | 627742e646c4 |
children | 3958dbde1223 |
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) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
35 |
110708
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
36 (defgroup shr nil |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
37 "Simple HTML Renderer" |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
38 :group 'mail) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
39 |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
40 (defcustom shr-max-image-proportion 0.9 |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
41 "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
|
42 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
|
43 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
|
44 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
|
45 fit these criteria." |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
46 :version "24.1" |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
47 :group 'shr |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
48 :type 'float) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
49 |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
50 (defcustom shr-blocked-images nil |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
51 "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
|
52 :version "24.1" |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
53 :group 'shr |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
54 :type 'regexp) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
55 |
110873
d98a67277730
shr,el: Allow shr table char to be customized.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110859
diff
changeset
|
56 (defcustom shr-table-line ?- |
d98a67277730
shr,el: Allow shr table char to be customized.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110859
diff
changeset
|
57 "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
|
58 :group 'shr |
d98a67277730
shr,el: Allow shr table char to be customized.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110859
diff
changeset
|
59 :type 'char) |
d98a67277730
shr,el: Allow shr table char to be customized.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110859
diff
changeset
|
60 |
d98a67277730
shr,el: Allow shr table char to be customized.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110859
diff
changeset
|
61 (defcustom shr-table-corner ?+ |
110917
3243e7055d49
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110898
diff
changeset
|
62 "Character used to draw table corner." |
3243e7055d49
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110898
diff
changeset
|
63 :group 'shr |
3243e7055d49
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110898
diff
changeset
|
64 :type 'char) |
3243e7055d49
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110898
diff
changeset
|
65 |
3243e7055d49
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110898
diff
changeset
|
66 (defcustom shr-hr-line ?- |
3243e7055d49
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110898
diff
changeset
|
67 "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
|
68 :group 'shr |
d98a67277730
shr,el: Allow shr table char to be customized.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110859
diff
changeset
|
69 :type 'char) |
d98a67277730
shr,el: Allow shr table char to be customized.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110859
diff
changeset
|
70 |
110966
0272ba632fc2
shr: make shr-width a defcustom, use it in shr-tag-img.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110957
diff
changeset
|
71 (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
|
72 "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
|
73 :type 'integer |
0272ba632fc2
shr: make shr-width a defcustom, use it in shr-tag-img.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110957
diff
changeset
|
74 :group 'shr) |
0272ba632fc2
shr: make shr-width a defcustom, use it in shr-tag-img.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110957
diff
changeset
|
75 |
110777
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
76 (defvar shr-content-function nil |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
77 "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
|
78 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
|
79 cid: URL as the argument.") |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
80 |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
81 ;;; Internal variables. |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
82 |
110708
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
83 (defvar shr-folding-mode nil) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
84 (defvar shr-state nil) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
85 (defvar shr-start nil) |
110747
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
86 (defvar shr-indentation 0) |
110777
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
87 (defvar shr-inhibit-images nil) |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
88 (defvar shr-list-mode nil) |
110810
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
89 (defvar shr-content-cache nil) |
110708
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
90 |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
91 (defvar shr-map |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
92 (let ((map (make-sparse-keymap))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
93 (define-key map "a" 'shr-show-alt-text) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
94 (define-key map "i" 'shr-browse-image) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
95 (define-key map "I" 'shr-insert-image) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
96 (define-key map "u" 'shr-copy-url) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
97 (define-key map "v" 'shr-browse-url) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
98 (define-key map "\r" 'shr-browse-url) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
99 map)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
100 |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
101 ;; Public functions and commands. |
110708
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
102 |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
103 ;;;###autoload |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
104 (defun shr-insert-document (dom) |
110810
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
105 (setq shr-content-cache nil) |
110708
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
106 (let ((shr-state nil) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
107 (shr-start nil)) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
108 (shr-descend (shr-transform-dom dom)))) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
109 |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
110 (defun shr-copy-url () |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
111 "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
|
112 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
|
113 redirects somewhere else." |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
114 (interactive) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
115 (let ((url (get-text-property (point) 'shr-url))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
116 (cond |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
117 ((not url) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
118 (message "No URL under point")) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
119 ;; Resolve redirected URLs. |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
120 ((equal url (car kill-ring)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
121 (url-retrieve |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
122 url |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
123 (lambda (a) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
124 (when (and (consp a) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
125 (eq (car a) :redirect)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
126 (with-temp-buffer |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
127 (insert (cadr a)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
128 (goto-char (point-min)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
129 ;; Remove common tracking junk from the URL. |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
130 (when (re-search-forward ".utm_.*" nil t) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
131 (replace-match "" t t)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
132 (message "Copied %s" (buffer-string)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
133 (copy-region-as-kill (point-min) (point-max))))))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
134 ;; Copy the URL to the kill ring. |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
135 (t |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
136 (with-temp-buffer |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
137 (insert url) |
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 (message "Copied %s" url)))))) |
110708
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
140 |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
141 (defun shr-show-alt-text () |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
142 "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
|
143 (interactive) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
144 (let ((text (get-text-property (point) 'shr-alt))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
145 (if (not text) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
146 (message "No image under point") |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
147 (message "%s" text)))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
148 |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
149 (defun shr-browse-image () |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
150 "Browse the image under point." |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
151 (interactive) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
152 (let ((url (get-text-property (point) 'shr-image))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
153 (if (not url) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
154 (message "No image under point") |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
155 (message "Browsing %s..." url) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
156 (browse-url url)))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
157 |
110810
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
158 (defun shr-insert-image () |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
159 "Insert the image under point into the buffer." |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
160 (interactive) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
161 (let ((url (get-text-property (point) 'shr-image))) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
162 (if (not url) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
163 (message "No image under point") |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
164 (message "Inserting %s..." url) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
165 (url-retrieve url 'shr-image-fetched |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
166 (list (current-buffer) (1- (point)) (point-marker)) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
167 t)))) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
168 |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
169 ;;; Utility functions. |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
170 |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
171 (defun shr-transform-dom (dom) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
172 (let ((result (list (pop dom)))) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
173 (dolist (arg (pop dom)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
174 (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
|
175 (cdr arg)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
176 result)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
177 (dolist (sub dom) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
178 (if (stringp sub) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
179 (push (cons :text sub) result) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
180 (push (shr-transform-dom sub) result))) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
181 (nreverse result))) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
182 |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
183 (defun shr-descend (dom) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
184 (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
|
185 (if (fboundp function) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
186 (funcall function (cdr dom)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
187 (shr-generic (cdr dom))))) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
188 |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
189 (defun shr-generic (cont) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
190 (dolist (sub cont) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
191 (cond |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
192 ((eq (car sub) :text) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
193 (shr-insert (cdr sub))) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
194 ((listp (cdr sub)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
195 (shr-descend sub))))) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
196 |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
197 (defun shr-insert (text) |
110917
3243e7055d49
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110898
diff
changeset
|
198 (when (and (eq shr-state 'image) |
3243e7055d49
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110898
diff
changeset
|
199 (not (string-match "\\`[ \t\n]+\\'" text))) |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
200 (insert "\n") |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
201 (setq shr-state nil)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
202 (cond |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
203 ((eq shr-folding-mode 'none) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
204 (insert text)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
205 (t |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
206 (let ((first t) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
207 column) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
208 (when (and (string-match "\\`[ \t\n]" text) |
110859
7aa4fdb60d57
shr.el (shr-insert): Don't insert double spaces.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110812
diff
changeset
|
209 (not (bolp)) |
7aa4fdb60d57
shr.el (shr-insert): Don't insert double spaces.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110812
diff
changeset
|
210 (not (eq (char-after (1- (point))) ? ))) |
110810
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
211 (insert " ")) |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
212 (dolist (elem (split-string text)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
213 (when (and (bolp) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
214 (> shr-indentation 0)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
215 (shr-indent)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
216 ;; The shr-start is a special variable that is used to pass |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
217 ;; upwards the first point in the buffer where the text really |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
218 ;; starts. |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
219 (unless shr-start |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
220 (setq shr-start (point))) |
110810
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
221 (insert elem) |
110917
3243e7055d49
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110898
diff
changeset
|
222 (when (> (shr-current-column) shr-width) |
110810
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
223 (if (not (search-backward " " (line-beginning-position) t)) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
224 (insert "\n") |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
225 (delete-char 1) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
226 (insert "\n") |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
227 (put-text-property (1- (point)) (point) 'shr-break t) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
228 (when (> shr-indentation 0) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
229 (shr-indent)) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
230 (end-of-line))) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
231 (insert " ")) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
232 (unless (string-match "[ \t\n]\\'" text) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
233 (delete-char -1)))))) |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
234 |
110917
3243e7055d49
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110898
diff
changeset
|
235 (defun shr-find-fill-point () |
3243e7055d49
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110898
diff
changeset
|
236 (let ((found nil)) |
3243e7055d49
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110898
diff
changeset
|
237 (while (and (not found) |
3243e7055d49
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110898
diff
changeset
|
238 (not (bolp))) |
3243e7055d49
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110898
diff
changeset
|
239 (when (or (eq (preceding-char) ? ) |
3243e7055d49
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110898
diff
changeset
|
240 (aref fill-find-break-point-function-table (preceding-char))) |
3243e7055d49
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110898
diff
changeset
|
241 (setq found (point))) |
3243e7055d49
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110898
diff
changeset
|
242 (backward-char 1)) |
3243e7055d49
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110898
diff
changeset
|
243 (or found |
3243e7055d49
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110898
diff
changeset
|
244 (end-of-line)))) |
3243e7055d49
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110898
diff
changeset
|
245 |
3243e7055d49
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110898
diff
changeset
|
246 (defun shr-current-column () |
3243e7055d49
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110898
diff
changeset
|
247 (let ((column 0)) |
3243e7055d49
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110898
diff
changeset
|
248 (save-excursion |
3243e7055d49
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110898
diff
changeset
|
249 (beginning-of-line) |
3243e7055d49
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110898
diff
changeset
|
250 (while (not (eolp)) |
3243e7055d49
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110898
diff
changeset
|
251 (incf column (char-width (following-char))) |
3243e7055d49
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110898
diff
changeset
|
252 (forward-char 1))) |
3243e7055d49
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110898
diff
changeset
|
253 column)) |
3243e7055d49
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110898
diff
changeset
|
254 |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
255 (defun shr-ensure-newline () |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
256 (unless (zerop (current-column)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
257 (insert "\n"))) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
258 |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
259 (defun shr-ensure-paragraph () |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
260 (unless (bobp) |
110898
069deed4cdec
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110873
diff
changeset
|
261 (if (<= (current-column) shr-indentation) |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
262 (unless (save-excursion |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
263 (forward-line -1) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
264 (looking-at " *$")) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
265 (insert "\n")) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
266 (if (save-excursion |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
267 (beginning-of-line) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
268 (looking-at " *$")) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
269 (insert "\n") |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
270 (insert "\n\n"))))) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
271 |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
272 (defun shr-indent () |
110898
069deed4cdec
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110873
diff
changeset
|
273 (when (> shr-indentation 0) |
069deed4cdec
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110873
diff
changeset
|
274 (insert (make-string shr-indentation ? )))) |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
275 |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
276 (defun shr-fontize-cont (cont &rest types) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
277 (let (shr-start) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
278 (shr-generic cont) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
279 (dolist (type types) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
280 (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
|
281 |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
282 (defun shr-add-font (start end type) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
283 (let ((overlay (make-overlay start end))) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
284 (overlay-put overlay 'face type))) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
285 |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
286 (defun shr-browse-url () |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
287 "Browse the URL under point." |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
288 (interactive) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
289 (let ((url (get-text-property (point) 'shr-url))) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
290 (if (not url) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
291 (message "No link under point") |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
292 (browse-url url)))) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
293 |
110708
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
294 (defun shr-image-fetched (status buffer start end) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
295 (when (and (buffer-name buffer) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
296 (not (plist-get status :error))) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
297 (url-store-in-cache (current-buffer)) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
298 (when (or (search-forward "\n\n" nil t) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
299 (search-forward "\r\n\r\n" nil t)) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
300 (let ((data (buffer-substring (point) (point-max)))) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
301 (with-current-buffer buffer |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
302 (let ((alt (buffer-substring start end)) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
303 (inhibit-read-only t)) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
304 (delete-region start end) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
305 (shr-put-image data start alt)))))) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
306 (kill-buffer (current-buffer))) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
307 |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
308 (defun shr-put-image (data point alt) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
309 (if (not (display-graphic-p)) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
310 (insert alt) |
110747
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
311 (let ((image (ignore-errors |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
312 (shr-rescale-image data)))) |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
313 (when image |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
314 (put-image image point alt))))) |
110708
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
315 |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
316 (defun shr-rescale-image (data) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
317 (if (or (not (fboundp 'imagemagick-types)) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
318 (not (get-buffer-window (current-buffer)))) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
319 (create-image data nil t) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
320 (let* ((image (create-image data nil t)) |
110747
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
321 (size (image-size image t)) |
110708
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
322 (width (car size)) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
323 (height (cdr size)) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
324 (edges (window-inside-pixel-edges |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
325 (get-buffer-window (current-buffer)))) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
326 (window-width (truncate (* shr-max-image-proportion |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
327 (- (nth 2 edges) (nth 0 edges))))) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
328 (window-height (truncate (* shr-max-image-proportion |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
329 (- (nth 3 edges) (nth 1 edges))))) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
330 scaled-image) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
331 (when (> height window-height) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
332 (setq image (or (create-image data 'imagemagick t |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
333 :height window-height) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
334 image)) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
335 (setq size (image-size image t))) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
336 (when (> (car size) window-width) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
337 (setq image (or |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
338 (create-image data 'imagemagick t |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
339 :width window-width) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
340 image))) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
341 image))) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
342 |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
343 (defun shr-get-image-data (url) |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
344 "Get image data for URL. |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
345 Return a string with image data." |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
346 (with-temp-buffer |
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
347 (mm-disable-multibyte) |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
348 (when (ignore-errors |
110957
627742e646c4
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110917
diff
changeset
|
349 (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
|
350 t) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
351 (when (or (search-forward "\n\n" nil t) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
352 (search-forward "\r\n\r\n" nil t)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
353 (buffer-substring (point) (point-max)))))) |
110708
4c31586ca1ca
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110704
diff
changeset
|
354 |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
355 (defun shr-heading (cont &rest types) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
356 (shr-ensure-paragraph) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
357 (apply #'shr-fontize-cont cont types) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
358 (shr-ensure-paragraph)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
359 |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
360 ;;; Tag-specific rendering rules. |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
361 |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
362 (defun shr-tag-p (cont) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
363 (shr-ensure-paragraph) |
110898
069deed4cdec
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110873
diff
changeset
|
364 (shr-indent) |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
365 (shr-generic cont) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
366 (shr-ensure-paragraph)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
367 |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
368 (defun shr-tag-b (cont) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
369 (shr-fontize-cont cont 'bold)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
370 |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
371 (defun shr-tag-i (cont) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
372 (shr-fontize-cont cont 'italic)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
373 |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
374 (defun shr-tag-em (cont) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
375 (shr-fontize-cont cont 'bold)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
376 |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
377 (defun shr-tag-u (cont) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
378 (shr-fontize-cont cont 'underline)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
379 |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
380 (defun shr-tag-s (cont) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
381 (shr-fontize-cont cont 'strike-through)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
382 |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
383 (defun shr-tag-a (cont) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
384 (let ((url (cdr (assq :href cont))) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
385 (start (point)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
386 shr-start) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
387 (shr-generic cont) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
388 (widget-convert-button |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
389 'link (or shr-start start) (point) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
390 :help-echo url) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
391 (put-text-property (or shr-start start) (point) 'keymap shr-map) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
392 (put-text-property (or shr-start start) (point) 'shr-url url))) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
393 |
110957
627742e646c4
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110917
diff
changeset
|
394 (defun shr-encode-url (url) |
627742e646c4
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110917
diff
changeset
|
395 "Encode URL." |
627742e646c4
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110917
diff
changeset
|
396 (browse-url-url-encode-chars url "[)$ ]")) |
627742e646c4
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110917
diff
changeset
|
397 |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
398 (defun shr-tag-img (cont) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
399 (when (and (> (current-column) 0) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
400 (not (eq shr-state 'image))) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
401 (insert "\n")) |
110957
627742e646c4
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110917
diff
changeset
|
402 (let ((alt (cdr (assq :alt cont))) |
627742e646c4
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110917
diff
changeset
|
403 (url (cdr (assq :src cont))) |
627742e646c4
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110917
diff
changeset
|
404 (width (cdr (assq :width cont)))) |
627742e646c4
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110917
diff
changeset
|
405 ;; Only respect align if width specified. |
627742e646c4
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110917
diff
changeset
|
406 (when width |
627742e646c4
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110917
diff
changeset
|
407 ;; Check that width is not larger than max width, otherwise ignore |
627742e646c4
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110917
diff
changeset
|
408 ;; align |
110966
0272ba632fc2
shr: make shr-width a defcustom, use it in shr-tag-img.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110957
diff
changeset
|
409 (let ((max-width (* shr-width (frame-char-width))) |
110957
627742e646c4
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110917
diff
changeset
|
410 (width (string-to-number width))) |
627742e646c4
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110917
diff
changeset
|
411 (when (< width max-width) |
627742e646c4
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110917
diff
changeset
|
412 (let ((align (cdr (assq :align cont)))) |
627742e646c4
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110917
diff
changeset
|
413 (cond ((string= align "right") |
627742e646c4
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110917
diff
changeset
|
414 (insert (propertize |
627742e646c4
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110917
diff
changeset
|
415 " " 'display |
627742e646c4
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110917
diff
changeset
|
416 `(space . (:align-to ,(list (- max-width width))))))) |
627742e646c4
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110917
diff
changeset
|
417 ((string= align "center") |
627742e646c4
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110917
diff
changeset
|
418 (insert (propertize |
627742e646c4
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110917
diff
changeset
|
419 " " 'display |
627742e646c4
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110917
diff
changeset
|
420 `(space . (:balign-to ,(list (- (/ max-width 2) width)))))))))))) |
627742e646c4
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110917
diff
changeset
|
421 (let ((start (point-marker))) |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
422 (when (zerop (length alt)) |
110957
627742e646c4
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110917
diff
changeset
|
423 (setq alt "[img]")) |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
424 (cond |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
425 ((and (not shr-inhibit-images) |
110957
627742e646c4
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110917
diff
changeset
|
426 (string-match "\\`cid:" url)) |
627742e646c4
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110917
diff
changeset
|
427 (let ((url (substring url (match-end 0))) |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
428 image) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
429 (if (or (not shr-content-function) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
430 (not (setq image (funcall shr-content-function url)))) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
431 (insert alt) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
432 (shr-put-image image (point) alt)))) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
433 ((or shr-inhibit-images |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
434 (and shr-blocked-images |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
435 (string-match shr-blocked-images url))) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
436 (setq shr-start (point)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
437 (let ((shr-state 'space)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
438 (if (> (length alt) 8) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
439 (shr-insert (substring alt 0 8)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
440 (shr-insert alt)))) |
110957
627742e646c4
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110917
diff
changeset
|
441 ((url-is-cached (shr-encode-url url)) |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
442 (shr-put-image (shr-get-image-data url) (point) alt)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
443 (t |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
444 (insert alt) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
445 (ignore-errors |
110957
627742e646c4
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110917
diff
changeset
|
446 (url-retrieve (shr-encode-url url) 'shr-image-fetched |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
447 (list (current-buffer) start (point-marker)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
448 t)))) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
449 (insert " ") |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
450 (put-text-property start (point) 'keymap shr-map) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
451 (put-text-property start (point) 'shr-alt alt) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
452 (put-text-property start (point) 'shr-image url) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
453 (setq shr-state 'image)))) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
454 |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
455 (defun shr-tag-pre (cont) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
456 (let ((shr-folding-mode 'none)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
457 (shr-ensure-newline) |
110898
069deed4cdec
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110873
diff
changeset
|
458 (shr-indent) |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
459 (shr-generic cont) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
460 (shr-ensure-newline))) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
461 |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
462 (defun shr-tag-blockquote (cont) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
463 (shr-ensure-paragraph) |
110898
069deed4cdec
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110873
diff
changeset
|
464 (shr-indent) |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
465 (let ((shr-indentation (+ shr-indentation 4))) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
466 (shr-generic cont)) |
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
467 (shr-ensure-paragraph)) |
110747
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
468 |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
469 (defun shr-tag-ul (cont) |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
470 (shr-ensure-paragraph) |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
471 (let ((shr-list-mode 'ul)) |
110810
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
472 (shr-generic cont)) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
473 (shr-ensure-paragraph)) |
110747
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
474 |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
475 (defun shr-tag-ol (cont) |
110810
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
476 (shr-ensure-paragraph) |
110747
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
477 (let ((shr-list-mode 1)) |
110810
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
478 (shr-generic cont)) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
479 (shr-ensure-paragraph)) |
110747
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
480 |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
481 (defun shr-tag-li (cont) |
110898
069deed4cdec
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110873
diff
changeset
|
482 (shr-ensure-paragraph) |
069deed4cdec
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110873
diff
changeset
|
483 (shr-indent) |
110757
d3001fd75795
shr.el (shr-tag-li): Get <li> indentation right.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110756
diff
changeset
|
484 (let* ((bullet |
d3001fd75795
shr.el (shr-tag-li): Get <li> indentation right.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110756
diff
changeset
|
485 (if (numberp shr-list-mode) |
d3001fd75795
shr.el (shr-tag-li): Get <li> indentation right.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110756
diff
changeset
|
486 (prog1 |
d3001fd75795
shr.el (shr-tag-li): Get <li> indentation right.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110756
diff
changeset
|
487 (format "%d " shr-list-mode) |
d3001fd75795
shr.el (shr-tag-li): Get <li> indentation right.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110756
diff
changeset
|
488 (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
|
489 "* ")) |
d3001fd75795
shr.el (shr-tag-li): Get <li> indentation right.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110756
diff
changeset
|
490 (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
|
491 (insert bullet) |
d3001fd75795
shr.el (shr-tag-li): Get <li> indentation right.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110756
diff
changeset
|
492 (shr-generic cont))) |
110747
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
493 |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
494 (defun shr-tag-br (cont) |
110756
9070b77b4a28
shr.el (shr-insert): Tweak line breaking.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110755
diff
changeset
|
495 (unless (bobp) |
110898
069deed4cdec
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110873
diff
changeset
|
496 (insert "\n") |
069deed4cdec
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110873
diff
changeset
|
497 (shr-indent)) |
110747
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
498 (shr-generic cont)) |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
499 |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
500 (defun shr-tag-h1 (cont) |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
501 (shr-heading cont 'bold 'underline)) |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
502 |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
503 (defun shr-tag-h2 (cont) |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
504 (shr-heading cont 'bold)) |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
505 |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
506 (defun shr-tag-h3 (cont) |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
507 (shr-heading cont 'italic)) |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
508 |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
509 (defun shr-tag-h4 (cont) |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
510 (shr-heading cont)) |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
511 |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
512 (defun shr-tag-h5 (cont) |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
513 (shr-heading cont)) |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
514 |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
515 (defun shr-tag-h6 (cont) |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
516 (shr-heading cont)) |
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
517 |
110810
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
518 (defun shr-tag-hr (cont) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
519 (shr-ensure-newline) |
110917
3243e7055d49
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110898
diff
changeset
|
520 (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
|
521 |
110790
1f25b03df4ad
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110778
diff
changeset
|
522 ;;; Table rendering algorithm. |
110747
0defef1647a5
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110740
diff
changeset
|
523 |
110778
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
524 ;; 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
|
525 ;; 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
|
526 ;; 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
|
527 ;; 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
|
528 ;; 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
|
529 ;; 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
|
530 ;; 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
|
531 ;; insert all these boxes into the main buffer. |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
532 (defun shr-tag-table (cont) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
533 (shr-ensure-paragraph) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
534 (setq cont (or (cdr (assq 'tbody cont)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
535 cont)) |
110777
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
536 (let* ((shr-inhibit-images t) |
110778
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
537 ;; Find all suggested widths. |
110777
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
538 (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
|
539 ;; 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
|
540 (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
|
541 ;; 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
|
542 ;; 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
|
543 ;; unbreakable text). |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
544 (sketch (shr-make-table cont suggested-widths)) |
110804
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
545 (sketch-widths (shr-table-widths sketch suggested-widths))) |
110778
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
546 ;; 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
|
547 (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
|
548 ;; 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
|
549 ;; 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
|
550 ;; into the tables. |
110777
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
551 (dolist (elem (shr-find-elements cont 'img)) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
552 (shr-tag-img (cdr elem)))) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
553 |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
554 (defun shr-find-elements (cont type) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
555 (let (result) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
556 (dolist (elem cont) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
557 (cond ((eq (car elem) type) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
558 (push elem result)) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
559 ((consp (cdr elem)) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
560 (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
|
561 (nreverse result))) |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
562 |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
563 (defun shr-insert-table (table widths) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
564 (shr-insert-table-ruler widths) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
565 (dolist (row table) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
566 (let ((start (point)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
567 (height (let ((max 0)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
568 (dolist (column row) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
569 (setq max (max max (cadr column)))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
570 max))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
571 (dotimes (i height) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
572 (shr-indent) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
573 (insert "|\n")) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
574 (dolist (column row) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
575 (goto-char start) |
110804
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
576 (let ((lines (nth 2 column)) |
110777
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
577 (overlay-lines (nth 3 column)) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
578 overlay overlay-line) |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
579 (dolist (line lines) |
110777
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
580 (setq overlay-line (pop overlay-lines)) |
110810
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
581 (end-of-line) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
582 (insert line "|") |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
583 (dolist (overlay overlay-line) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
584 (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
|
585 (- (point) (nth 1 overlay) 1))) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
586 (properties (nth 2 overlay))) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
587 (while properties |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
588 (overlay-put o (pop properties) (pop properties))))) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
589 (forward-line 1)) |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
590 ;; 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
|
591 ;; possibly. |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
592 (dotimes (i (- height (length lines))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
593 (end-of-line) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
594 (insert (make-string (length (car lines)) ? ) "|") |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
595 (forward-line 1))))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
596 (shr-insert-table-ruler widths))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
597 |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
598 (defun shr-insert-table-ruler (widths) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
599 (shr-indent) |
110873
d98a67277730
shr,el: Allow shr table char to be customized.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110859
diff
changeset
|
600 (insert shr-table-corner) |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
601 (dotimes (i (length widths)) |
110873
d98a67277730
shr,el: Allow shr table char to be customized.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110859
diff
changeset
|
602 (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
|
603 (insert "\n")) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
604 |
110804
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
605 (defun shr-table-widths (table suggested-widths) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
606 (let* ((length (length suggested-widths)) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
607 (widths (make-vector length 0)) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
608 (natural-widths (make-vector length 0))) |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
609 (dolist (row table) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
610 (let ((i 0)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
611 (dolist (column row) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
612 (aset widths i (max (aref widths i) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
613 (car column))) |
110804
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
614 (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
|
615 (cadr column))) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
616 (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
|
617 (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
|
618 (apply '+ (append widths nil)))) |
110804
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
619 (expanded-columns 0)) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
620 (when (> extra 0) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
621 (dotimes (i length) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
622 ;; 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
|
623 ;; want to allow the column to expand. |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
624 (when (> (aref natural-widths i) (aref widths i)) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
625 (setq expanded-columns (1+ expanded-columns)))) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
626 (dotimes (i length) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
627 (when (> (aref natural-widths i) (aref widths i)) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
628 (aset widths i (min |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
629 (1+ (aref natural-widths i)) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
630 (+ (/ extra expanded-columns) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
631 (aref widths i)))))))) |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
632 widths)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
633 |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
634 (defun shr-make-table (cont widths &optional fill) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
635 (let ((trs nil)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
636 (dolist (row cont) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
637 (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
|
638 (let ((tds nil) |
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
639 (columns (cdr row)) |
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
640 (i 0) |
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
641 column) |
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
642 (while (< i (length widths)) |
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
643 (setq column (pop columns)) |
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
644 (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
|
645 (null column)) |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
646 (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
|
647 tds) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
648 (setq i (1+ i)))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
649 (push (nreverse tds) trs)))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
650 (nreverse trs))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
651 |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
652 (defun shr-render-td (cont width fill) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
653 (with-temp-buffer |
110810
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
654 (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
|
655 (if cache |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
656 (insert cache) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
657 (let ((shr-width width) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
658 (shr-indentation 0)) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
659 (shr-generic cont)) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
660 (delete-region |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
661 (point) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
662 (+ (point) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
663 (skip-chars-backward " \t\n"))) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
664 (push (cons (cons width cont) (buffer-string)) |
07053df95af6
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110804
diff
changeset
|
665 shr-content-cache))) |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
666 (goto-char (point-min)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
667 (let ((max 0)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
668 (while (not (eobp)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
669 (end-of-line) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
670 (setq max (max max (current-column))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
671 (forward-line 1)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
672 (when fill |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
673 (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
|
674 ;; 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
|
675 ;; line here. |
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
676 (if (zerop (buffer-size)) |
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
677 (insert (make-string width ? )) |
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
678 ;; Otherwise, fill the buffer. |
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
679 (while (not (eobp)) |
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
680 (end-of-line) |
5a595f515d1c
shr.el (shr-render-td): Allow blank/missing <TD>s.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110777
diff
changeset
|
681 (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
|
682 (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
|
683 (forward-line 1)))) |
110804
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
684 (if fill |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
685 (list max |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
686 (count-lines (point-min) (point-max)) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
687 (split-string (buffer-string) "\n") |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
688 (shr-collect-overlays)) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
689 (list max |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
690 (shr-natural-width)))))) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
691 |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
692 (defun shr-natural-width () |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
693 (goto-char (point-min)) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
694 (let ((current 0) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
695 (max 0)) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
696 (while (not (eobp)) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
697 (end-of-line) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
698 (setq current (+ current (current-column))) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
699 (unless (get-text-property (point) 'shr-break) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
700 (setq max (max max current) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
701 current 0)) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
702 (forward-line 1)) |
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
703 max)) |
110777
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
704 |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
705 (defun shr-collect-overlays () |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
706 (save-excursion |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
707 (goto-char (point-min)) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
708 (let ((overlays nil)) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
709 (while (not (eobp)) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
710 (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
|
711 overlays) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
712 (forward-line 1)) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
713 (nreverse overlays)))) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
714 |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
715 (defun shr-overlays-in-region (start end) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
716 (let (result) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
717 (dolist (overlay (overlays-in start end)) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
718 (push (list (if (> start (overlay-start overlay)) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
719 (- end start) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
720 (- end (overlay-start overlay))) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
721 (if (< end (overlay-end overlay)) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
722 0 |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
723 (- end (overlay-end overlay))) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
724 (overlay-properties overlay)) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
725 result)) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
726 (nreverse result))) |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
727 |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
728 (defun shr-pro-rate-columns (columns) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
729 (let ((total-percentage 0) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
730 (widths (make-vector (length columns) 0))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
731 (dotimes (i (length columns)) |
110804
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
732 (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
|
733 (setq total-percentage (/ 1.0 total-percentage)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
734 (dotimes (i (length columns)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
735 (aset widths i (max (truncate (* (aref columns i) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
736 total-percentage |
110804
30fed27e97bc
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110792
diff
changeset
|
737 (- shr-width (1+ (length columns))))) |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
738 10))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
739 widths)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
740 |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
741 ;; 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
|
742 (defun shr-column-specs (cont) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
743 (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
|
744 (dolist (row cont) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
745 (when (eq (car row) 'tr) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
746 (let ((i 0)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
747 (dolist (column (cdr row)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
748 (when (memq (car column) '(td th)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
749 (let ((width (cdr (assq :width (cdr column))))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
750 (when (and width |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
751 (string-match "\\([0-9]+\\)%" width)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
752 (aset columns i |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
753 (/ (string-to-number (match-string 1 width)) |
110777
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
754 100.0)))) |
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
755 (setq i (1+ i))))))) |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
756 columns)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
757 |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
758 (defun shr-count (cont elem) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
759 (let ((i 0)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
760 (dolist (sub cont) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
761 (when (eq (car sub) elem) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
762 (setq i (1+ i)))) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
763 i)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
764 |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
765 (defun shr-max-columns (cont) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
766 (let ((max 0)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
767 (dolist (row cont) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
768 (when (eq (car row) 'tr) |
110777
895607aec71e
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110774
diff
changeset
|
769 (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
|
770 (shr-count (cdr row) 'th)))))) |
110763
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
771 max)) |
0fe64d68a522
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110757
diff
changeset
|
772 |
110704
016990bf37ad
lisp/gnus/shr.el (shr): Fix typo in provide call.
Juanma Barranquero <lekktu@gmail.com>
parents:
110698
diff
changeset
|
773 (provide 'shr) |
110698
74bad2d7bddd
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
774 |
74bad2d7bddd
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff
changeset
|
775 ;;; shr.el ends here |