annotate lisp/gnus/shr.el @ 110714:34826102748f

Do not autoload appt-delete. * lisp/calendar/appt.el (appt-delete): Don't autoload it (you can't use it without having used appt.el already).
author Glenn Morris <rgm@gnu.org>
date Sat, 02 Oct 2010 18:56:11 -0700
parents 4c31586ca1ca
children ed9ff0bf7851
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
110708
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
33 (defgroup shr nil
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
34 "Simple HTML Renderer"
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
35 :group 'mail)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
36
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
37 (defcustom shr-max-image-proportion 0.9
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
38 "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
39 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
40 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
41 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
42 fit these criteria."
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
43 :version "24.1"
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
44 :group 'shr
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
45 :type 'float)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
46
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
47 (defcustom shr-blocked-images nil
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
48 "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
49 :version "24.1"
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
50 :group 'shr
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
51 :type 'regexp)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
52
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
53 (defvar shr-folding-mode nil)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
54 (defvar shr-state nil)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
55 (defvar shr-start nil)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
56
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
57 (defvar shr-width 70)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
58
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
59 (defun shr-transform-dom (dom)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
60 (let ((result (list (pop dom))))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
61 (dolist (arg (pop dom))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
62 (push (cons (intern (concat ":" (symbol-name (car arg))) obarray)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
63 (cdr arg))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
64 result))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
65 (dolist (sub dom)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
66 (if (stringp sub)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
67 (push (cons :text sub) result)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
68 (push (shr-transform-dom sub) result)))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
69 (nreverse result)))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
70
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
71 ;;;###autoload
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
72 (defun shr-insert-document (dom)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
73 (let ((shr-state nil)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
74 (shr-start nil))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
75 (shr-descend (shr-transform-dom dom))))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
76
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
77 (defun shr-descend (dom)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
78 (let ((function (intern (concat "shr-" (symbol-name (car dom))) obarray)))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
79 (if (fboundp function)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
80 (funcall function (cdr dom))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
81 (shr-generic (cdr dom)))))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
82
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
83 (defun shr-generic (cont)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
84 (dolist (sub cont)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
85 (cond
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
86 ((eq (car sub) :text)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
87 (shr-insert (cdr sub)))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
88 ((consp (cdr sub))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
89 (shr-descend sub)))))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
90
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
91 (defun shr-p (cont)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
92 (shr-ensure-newline)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
93 (insert "\n")
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
94 (shr-generic cont)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
95 (insert "\n"))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
96
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
97 (defun shr-b (cont)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
98 (shr-fontize-cont cont 'bold))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
99
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
100 (defun shr-i (cont)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
101 (shr-fontize-cont cont 'italic))
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 (defun shr-u (cont)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
104 (shr-fontize-cont cont 'underline))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
105
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
106 (defun shr-s (cont)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
107 (shr-fontize-cont cont 'strikethru))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
108
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
109 (defun shr-fontize-cont (cont type)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
110 (let (shr-start)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
111 (shr-generic cont)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
112 (shr-add-font shr-start (point) type)))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
113
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
114 (defun shr-add-font (start end type)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
115 (let ((overlay (make-overlay start end)))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
116 (overlay-put overlay 'face type)))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
117
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
118 (defun shr-a (cont)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
119 (let ((url (cdr (assq :href cont)))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
120 shr-start)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
121 (shr-generic cont)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
122 (widget-convert-button
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
123 'link shr-start (point)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
124 :action 'shr-browse-url
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
125 :url url
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
126 :keymap widget-keymap
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
127 :help-echo url)))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
128
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
129 (defun shr-browse-url (widget &rest stuff)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
130 (browse-url (widget-get widget :url)))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
131
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
132 (defun shr-img (cont)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
133 (let ((start (point-marker)))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
134 (let ((alt (cdr (assq :alt cont)))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
135 (url (cdr (assq :src cont))))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
136 (when (zerop (length alt))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
137 (setq alt "[img]"))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
138 (cond
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
139 ((and shr-blocked-images
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
140 (string-match shr-blocked-images url))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
141 (insert alt))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
142 ((url-is-cached (browse-url-url-encode-chars url "[&)$ ]"))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
143 (shr-put-image (shr-get-image-data url) (point) alt))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
144 (t
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
145 (insert alt)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
146 (url-retrieve url 'shr-image-fetched
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
147 (list (current-buffer) start (point-marker))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
148 t)))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
149 (insert " ")
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
150 (setq shr-state 'image))))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
151
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
152 (defun shr-image-fetched (status buffer start end)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
153 (when (and (buffer-name buffer)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
154 (not (plist-get status :error)))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
155 (url-store-in-cache (current-buffer))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
156 (when (or (search-forward "\n\n" nil t)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
157 (search-forward "\r\n\r\n" nil t))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
158 (let ((data (buffer-substring (point) (point-max))))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
159 (with-current-buffer buffer
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
160 (let ((alt (buffer-substring start end))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
161 (inhibit-read-only t))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
162 (delete-region start end)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
163 (shr-put-image data start alt))))))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
164 (kill-buffer (current-buffer)))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
165
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
166 (defun shr-put-image (data point alt)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
167 (if (not (display-graphic-p))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
168 (insert alt)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
169 (let ((image (shr-rescale-image data)))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
170 (put-image image point alt))))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
171
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
172 (defun shr-rescale-image (data)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
173 (if (or (not (fboundp 'imagemagick-types))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
174 (not (get-buffer-window (current-buffer))))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
175 (create-image data nil t)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
176 (let* ((image (create-image data nil t))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
177 (size (image-size image))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
178 (width (car size))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
179 (height (cdr size))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
180 (edges (window-inside-pixel-edges
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
181 (get-buffer-window (current-buffer))))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
182 (window-width (truncate (* shr-max-image-proportion
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
183 (- (nth 2 edges) (nth 0 edges)))))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
184 (window-height (truncate (* shr-max-image-proportion
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
185 (- (nth 3 edges) (nth 1 edges)))))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
186 scaled-image)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
187 (when (> height window-height)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
188 (setq image (or (create-image data 'imagemagick t
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
189 :height window-height)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
190 image))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
191 (setq size (image-size image t)))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
192 (when (> (car size) window-width)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
193 (setq image (or
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
194 (create-image data 'imagemagick t
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
195 :width window-width)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
196 image)))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
197 image)))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
198
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
199 (defun shr-pre (cont)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
200 (let ((shr-folding-mode nil))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
201 (shr-ensure-newline)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
202 (shr-generic cont)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
203 (shr-ensure-newline)))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
204
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
205 (defun shr-blockquote (cont)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
206 (shr-pre cont))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
207
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
208 (defun shr-ensure-newline ()
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
209 (unless (zerop (current-column))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
210 (insert "\n")))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
211
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
212 (defun shr-insert (text)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
213 (when (eq shr-state 'image)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
214 (insert "\n")
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
215 (setq shr-state nil))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
216 (cond
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
217 ((eq shr-folding-mode 'none)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
218 (insert t))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
219 (t
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
220 (let (column)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
221 (dolist (elem (split-string text))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
222 (setq column (current-column))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
223 (when (plusp column)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
224 (if (> (+ column (length elem) 1) shr-width)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
225 (insert "\n")
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
226 (insert " ")))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
227 ;; The shr-start is a special variable that is used to pass
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
228 ;; upwards the first point in the buffer where the text really
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
229 ;; starts.
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
230 (unless shr-start
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
231 (setq shr-start (point)))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
232 (insert elem))))))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
233
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
234 (defun shr-get-image-data (url)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
235 "Get image data for URL.
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
236 Return a string with image data."
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
237 (with-temp-buffer
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
238 (mm-disable-multibyte)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
239 (url-cache-extract (url-cache-create-filename url))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
240 (when (or (search-forward "\n\n" nil t)
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
241 (search-forward "\r\n\r\n" nil t))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
242 (buffer-substring (point) (point-max)))))
4c31586ca1ca Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents: 110704
diff changeset
243
110704
016990bf37ad lisp/gnus/shr.el (shr): Fix typo in provide call.
Juanma Barranquero <lekktu@gmail.com>
parents: 110698
diff changeset
244 (provide 'shr)
110698
74bad2d7bddd Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
245
74bad2d7bddd Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
diff changeset
246 ;;; shr.el ends here