14
|
1 ;;; w3-display.el --- display engine v99999
|
|
2 ;; Author: wmperry
|
24
|
3 ;; Created: 1997/02/15 23:38:28
|
|
4 ;; Version: 1.128
|
14
|
5 ;; Keywords: faces, help, hypermedia
|
|
6
|
|
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
8 ;;; Copyright (c) 1996 by William M. Perry (wmperry@cs.indiana.edu)
|
16
|
9 ;;; Copyright (c) 1996, 1997 Free Software Foundation, Inc.
|
14
|
10 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
11 ;;;
|
|
12 ;;; This file is part of GNU Emacs.
|
|
13 ;;;
|
|
14 ;;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
15 ;;; it under the terms of the GNU General Public License as published by
|
|
16 ;;; the Free Software Foundation; either version 2, or (at your option)
|
|
17 ;;; any later version.
|
|
18 ;;;
|
|
19 ;;; GNU Emacs is distributed in the hope that it will be useful,
|
|
20 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
22 ;;; GNU General Public License for more details.
|
|
23 ;;;
|
|
24 ;;; You should have received a copy of the GNU General Public License
|
|
25 ;;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
26 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
27 ;;; Boston, MA 02111-1307, USA.
|
|
28 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
29 (require 'cl)
|
|
30 (require 'css)
|
|
31 (require 'font)
|
|
32 (require 'w3-widget)
|
|
33 (require 'w3-imap)
|
|
34
|
22
|
35 (define-widget-keywords :emacspeak-help)
|
16
|
36 (autoload 'sentence-ify "flame")
|
|
37 (autoload 'string-ify "flame")
|
|
38 (autoload '*flame "flame")
|
|
39 (if (not (fboundp 'flatten)) (autoload 'flatten "flame"))
|
|
40 (defvar w3-cookie-cache nil)
|
|
41
|
14
|
42 (defmacro w3-d-s-var-def (var)
|
|
43 (` (make-variable-buffer-local (defvar (, var) nil))))
|
|
44
|
|
45 (w3-d-s-var-def w3-display-open-element-stack)
|
|
46 (w3-d-s-var-def w3-display-alignment-stack)
|
|
47 (w3-d-s-var-def w3-display-list-stack)
|
16
|
48 (w3-d-s-var-def w3-display-form-id)
|
14
|
49 (w3-d-s-var-def w3-display-whitespace-stack)
|
|
50 (w3-d-s-var-def w3-display-font-family-stack)
|
|
51 (w3-d-s-var-def w3-display-font-weight-stack)
|
|
52 (w3-d-s-var-def w3-display-font-variant-stack)
|
|
53 (w3-d-s-var-def w3-display-font-size-stack)
|
|
54 (w3-d-s-var-def w3-face-color)
|
16
|
55 (w3-d-s-var-def w3-face-background-color)
|
14
|
56 (w3-d-s-var-def w3-active-faces)
|
|
57 (w3-d-s-var-def w3-active-voices)
|
|
58 (w3-d-s-var-def w3-current-form-number)
|
|
59 (w3-d-s-var-def w3-face-font-family)
|
|
60 (w3-d-s-var-def w3-face-font-weight)
|
|
61 (w3-d-s-var-def w3-face-font-variant)
|
|
62 (w3-d-s-var-def w3-face-font-size)
|
|
63 (w3-d-s-var-def w3-face-font-family)
|
|
64 (w3-d-s-var-def w3-face-font-size)
|
16
|
65 (w3-d-s-var-def w3-face-font-style)
|
14
|
66 (w3-d-s-var-def w3-face-font-spec)
|
|
67 (w3-d-s-var-def w3-face-text-decoration)
|
|
68 (w3-d-s-var-def w3-face-face)
|
|
69 (w3-d-s-var-def w3-face-descr)
|
|
70 (w3-d-s-var-def w3-face-pixmap)
|
|
71 (w3-d-s-var-def w3-display-css-properties)
|
|
72
|
|
73 (eval-when-compile
|
|
74 (defmacro w3-get-attribute (attr)
|
|
75 (` (cdr-safe (assq (, attr) args))))
|
|
76
|
|
77 (defmacro w3-get-face-info (info)
|
|
78 (let ((var (intern (format "w3-face-%s" info))))
|
|
79 (` (push (w3-get-style-info (quote (, info)) node (car (, var)))
|
|
80 (, var)))))
|
|
81
|
|
82 (defmacro w3-pop-face-info (info)
|
|
83 (let ((var (intern (format "w3-face-%s" info))))
|
|
84 (` (pop (, var)))))
|
|
85
|
|
86 (defmacro w3-get-all-face-info ()
|
|
87 (`
|
|
88 (progn
|
|
89 (w3-get-face-info font-family)
|
16
|
90 (w3-get-face-info font-style)
|
14
|
91 (w3-get-face-info font-weight)
|
|
92 (w3-get-face-info font-variant)
|
|
93 (w3-get-face-info font-size)
|
|
94 (w3-get-face-info text-decoration)
|
|
95 ;;(w3-get-face-info pixmap)
|
|
96 (w3-get-face-info color)
|
16
|
97 (w3-get-face-info background-color)
|
14
|
98 (setq w3-face-font-spec (make-font
|
|
99 :weight (car w3-face-font-weight)
|
|
100 :family (car w3-face-font-family)
|
|
101 :size (car w3-face-font-size))))))
|
|
102
|
|
103 (defmacro w3-pop-all-face-info ()
|
|
104 (`
|
|
105 (progn
|
|
106 (w3-pop-face-info font-family)
|
|
107 (w3-pop-face-info font-weight)
|
|
108 (w3-pop-face-info font-variant)
|
|
109 (w3-pop-face-info font-size)
|
16
|
110 (w3-pop-face-info font-style)
|
14
|
111 (w3-pop-face-info text-decoration)
|
|
112 ;;(w3-pop-face-info pixmap)
|
|
113 (w3-pop-face-info color)
|
16
|
114 (w3-pop-face-info background-color))))
|
14
|
115
|
|
116 )
|
|
117
|
16
|
118 (defvar w3-display-same-buffer nil)
|
14
|
119 (defvar w3-face-cache nil "Cache for w3-face-for-element")
|
|
120 (defvar w3-face-index 0)
|
|
121 (defvar w3-image-widgets-waiting nil)
|
|
122
|
|
123 (make-variable-buffer-local 'w3-last-fill-pos)
|
|
124
|
|
125 (defconst w3-fill-prefixes-vector
|
|
126 (let ((len 0)
|
|
127 (prefix-vector (make-vector 80 nil)))
|
|
128 (while (< len 80)
|
|
129 (aset prefix-vector len (make-string len ? ))
|
|
130 (setq len (1+ len)))
|
|
131 prefix-vector))
|
|
132
|
|
133 (defconst w3-line-breaks-vector
|
|
134 (let ((len 0)
|
|
135 (breaks-vector (make-vector 10 nil)))
|
|
136 (while (< len 10)
|
|
137 (aset breaks-vector len (make-string len ?\n))
|
|
138 (setq len (1+ len)))
|
|
139 breaks-vector))
|
|
140
|
|
141 (defun w3-pause ()
|
|
142 (cond
|
|
143 (w3-running-FSF19 (sit-for 0))
|
|
144 (w3-running-xemacs
|
|
145 (sit-for 0))
|
|
146 ;; (if (and (not (sit-for 0)) (input-pending-p))
|
|
147 ;; (condition-case ()
|
|
148 ;; (dispatch-event (next-command-event))
|
|
149 ;; (error nil)))
|
|
150 (t (sit-for 0))))
|
|
151
|
|
152 (defmacro w3-get-pad-string (len)
|
|
153 (` (cond
|
|
154 ((< (, len) 0)
|
|
155 "")
|
|
156 ((< (, len) 80)
|
|
157 (aref w3-fill-prefixes-vector (, len)))
|
|
158 (t (make-string (, len) ? )))))
|
|
159
|
|
160 (defsubst w3-set-fill-prefix-length (len)
|
|
161 (setq fill-prefix (if (< len (- (or w3-strict-width (window-width)) 4))
|
|
162 (w3-get-pad-string len)
|
|
163 (url-warn
|
|
164 'html
|
|
165 "Runaway indentation! Too deep for window width!")
|
|
166 fill-prefix)))
|
|
167
|
|
168 (defsubst w3-get-style-info (info node &optional default)
|
|
169 (or (cdr-safe (assq info w3-display-css-properties)) default))
|
|
170
|
|
171 (defun w3-decode-area-coords (str)
|
|
172 (let (retval)
|
|
173 (while (string-match "\\([ \t0-9]+\\),\\([ \t0-9]+\\)" str)
|
|
174 (setq retval (cons (vector (string-to-int (match-string 1 str))
|
|
175 (string-to-int (match-string 2 str))) retval)
|
|
176 str (substring str (match-end 0) nil)))
|
|
177 (if (string-match "\\([0-9]+\\)" str)
|
|
178 (setq retval (cons (vector (+ (aref (car retval) 0)
|
|
179 (string-to-int (match-string 1 str)))
|
|
180 (aref (car retval) 1)) retval)))
|
|
181 (nreverse retval)))
|
|
182
|
|
183 (defun w3-normalize-color (color)
|
|
184 (cond
|
|
185 ((valid-color-name-p color)
|
|
186 color)
|
|
187 ((valid-color-name-p (concat "#" color))
|
|
188 (concat "#" color))
|
|
189 ((string-match "[ \t\r\n]" color)
|
|
190 (w3-normalize-color
|
|
191 (mapconcat (function (lambda (x) (if (memq x '(?\t ?\r ?\n ? )) ""
|
|
192 (char-to-string x)))) color "")))
|
|
193 ((valid-color-name-p (font-normalize-color color))
|
|
194 (font-normalize-color color))
|
|
195 (t
|
|
196 (w3-warn 'html (format "Bad color specification: %s" color))
|
|
197 nil)))
|
|
198
|
|
199 (defsubst w3-voice-for-element (node)
|
|
200 (if (featurep 'emacspeak)
|
|
201 (let (family gain left right pitch pitch-range stress richness voice)
|
|
202 (setq family (w3-get-style-info 'voice-family node)
|
|
203 gain (w3-get-style-info 'gain node)
|
|
204 left (w3-get-style-info 'left-volume node)
|
|
205 right (w3-get-style-info 'right-volume node)
|
|
206 pitch (w3-get-style-info 'pitch node)
|
|
207 pitch-range (w3-get-style-info 'pitch-range node)
|
|
208 stress (w3-get-style-info 'stress node)
|
|
209 richness (w3-get-style-info 'richness node))
|
|
210 (if (or family gain left right pitch pitch-range stress richness)
|
|
211 (setq voice (dtk-personality-from-speech-style
|
|
212 (make-dtk-speech-style :family (or family 'paul)
|
|
213 :gain (or gain 5)
|
|
214 :left-volume (or left 5)
|
|
215 :right-volume (or right 5)
|
|
216 :average-pitch (or pitch 5)
|
|
217 :pitch-range (or pitch-range 5)
|
|
218 :stress (or stress 5)
|
|
219 :richness (or richness 5))))
|
|
220 (setq voice nil))
|
|
221 (or voice (car w3-active-voices)))))
|
|
222
|
|
223 (defun w3-make-face-emacs19 (name &optional doc-string temporary)
|
|
224 "Defines and returns a new FACE described by DOC-STRING.
|
|
225 If the face already exists, it is unmodified.
|
|
226 If TEMPORARY is non-nil, this face will cease to exist if not in use."
|
|
227 (make-face name))
|
|
228
|
|
229 (cond
|
|
230 ((not (fboundp 'make-face))
|
|
231 (fset 'w3-make-face 'ignore))
|
|
232 (w3-running-xemacs
|
|
233 (fset 'w3-make-face 'make-face))
|
|
234 (t
|
|
235 (fset 'w3-make-face 'w3-make-face-emacs19)))
|
|
236
|
|
237 (defsubst w3-face-for-element (node)
|
|
238 (w3-get-all-face-info)
|
|
239 (if (car w3-face-text-decoration)
|
|
240 (set-font-style-by-keywords w3-face-font-spec
|
|
241 (car w3-face-text-decoration)))
|
|
242 (if w3-face-font-variant
|
|
243 (set-font-style-by-keywords w3-face-font-spec
|
|
244 (car w3-face-font-variant)))
|
16
|
245 (if w3-face-font-style
|
|
246 (set-font-style-by-keywords w3-face-font-spec
|
|
247 (car w3-face-font-style)))
|
14
|
248 (setq w3-face-descr (list w3-face-font-spec
|
|
249 (car w3-face-color)
|
16
|
250 (car w3-face-background-color))
|
14
|
251 w3-face-face (cdr-safe (assoc w3-face-descr w3-face-cache)))
|
|
252 (if (or w3-face-face (not (or (car w3-face-color)
|
16
|
253 (car w3-face-background-color)
|
14
|
254 w3-face-font-spec)))
|
|
255 nil ; Do nothing, we got it already
|
|
256 (setq w3-face-face
|
|
257 (w3-make-face (intern (format "w3-style-face-%05d" w3-face-index))
|
|
258 "An Emacs-W3 face... don't edit by hand." t)
|
|
259 w3-face-index (1+ w3-face-index))
|
|
260 (if w3-face-font-spec
|
|
261 (set-face-font w3-face-face w3-face-font-spec))
|
|
262 (if (car w3-face-color)
|
|
263 (set-face-foreground w3-face-face (car w3-face-color)))
|
16
|
264 (if (car w3-face-background-color)
|
|
265 (set-face-background w3-face-face (car w3-face-background-color)))
|
14
|
266 ;;(set-face-background-pixmap w3-face-face w3-face-pixmap)
|
|
267 (setq w3-face-cache (cons
|
|
268 (cons w3-face-descr w3-face-face)
|
|
269 w3-face-cache)))
|
|
270 w3-face-face)
|
|
271
|
|
272 (defun w3-normalize-spaces (string)
|
|
273 ;; nuke spaces in the middle
|
|
274 (while (string-match "[ \t\r\n][ \r\t\n]+" string)
|
|
275 (setq string (concat (substring string 0 (1+ (match-beginning 0)))
|
|
276 (substring string (match-end 0)))))
|
|
277
|
|
278 ;; nuke spaces at the beginning
|
|
279 (if (string-match "^[ \t\r\n]+" string)
|
|
280 (setq string (substring string (match-end 0))))
|
|
281
|
|
282 ;; nuke spaces at the end
|
|
283 (if (string-match "[ \t\n\r]+$" string)
|
|
284 (setq string (substring string 0 (match-beginning 0))))
|
|
285 string)
|
|
286
|
|
287 (defvar w3-bullets
|
|
288 '((disc . ?*)
|
|
289 (circle . ?o)
|
|
290 (square . ?#)
|
16
|
291 (none . ? )
|
14
|
292 )
|
|
293 "*An assoc list of unordered list types mapping to characters to use
|
|
294 as the bullet character.")
|
|
295
|
|
296
|
|
297 (defsubst w3-display-line-break (n)
|
|
298 (if (or
|
|
299 (memq (car w3-display-whitespace-stack) '(pre nowrap)) ; Been told
|
|
300 (= w3-last-fill-pos (point))
|
|
301 (> w3-last-fill-pos (point-max)))
|
|
302 (if (/= (preceding-char) ?\n) (setq n (1+ n))) ; at least put one line in
|
|
303 (let ((fill-column (max (1+ (length fill-prefix)) fill-column))
|
|
304 width)
|
|
305 (case (car w3-display-alignment-stack)
|
|
306 (center
|
|
307 (fill-region-as-paragraph w3-last-fill-pos (point))
|
|
308 (center-region w3-last-fill-pos (point-max)))
|
|
309 ((justify full)
|
|
310 (fill-region-as-paragraph w3-last-fill-pos (point) t))
|
|
311 (right
|
|
312 (fill-region-as-paragraph w3-last-fill-pos (point))
|
|
313 (goto-char w3-last-fill-pos)
|
|
314 (catch 'fill-exit
|
|
315 (while (re-search-forward ".$" nil t)
|
|
316 (if (>= (setq width (current-column)) fill-column)
|
|
317 nil ; already justified, or error
|
|
318 (beginning-of-line)
|
|
319 (insert-char ? (- fill-column width))
|
|
320 (end-of-line)
|
|
321 (if (eobp)
|
|
322 (throw 'fill-exit t))
|
|
323 (condition-case ()
|
|
324 (forward-char 1)
|
|
325 (error (throw 'fill-exit t))))))
|
|
326 )
|
|
327 (otherwise ; Default is left justification
|
|
328 (fill-region-as-paragraph w3-last-fill-pos (point)))
|
|
329 ))
|
|
330 (setq n (1- n)))
|
|
331 (setq w3-last-fill-pos (point-max))
|
|
332 (insert (cond
|
|
333 ((<= n 0) "")
|
|
334 ((< n 10)
|
|
335 (aref w3-line-breaks-vector n))
|
|
336 (t
|
|
337 (make-string n ?\n)))))
|
|
338
|
|
339 (defsubst w3-munge-line-breaks-p ()
|
|
340 (eq (car w3-display-whitespace-stack) 'pre))
|
|
341
|
|
342 (defvar w3-display-nil-face (w3-make-face nil "Stub face... don't ask." t))
|
|
343
|
|
344 (defvar w3-scratch-start-point nil)
|
|
345
|
|
346 (defsubst w3-handle-string-content (string)
|
|
347 (setq w3-scratch-start-point (point))
|
|
348 (insert string)
|
|
349 (if (w3-munge-line-breaks-p)
|
|
350 (progn
|
|
351 (goto-char w3-scratch-start-point)
|
|
352 (if (not (search-forward "\n" nil t))
|
|
353 (subst-char-in-region w3-scratch-start-point (point-max) ?\r ?\n)
|
|
354 (subst-char-in-region w3-scratch-start-point (point-max) ?\r ? )))
|
|
355 (goto-char w3-scratch-start-point)
|
|
356 (while (re-search-forward
|
|
357 " [ \t\n\r]+\\|[\t\n\r][ \t\n\r]*"
|
|
358 nil 'move)
|
|
359 (replace-match " "))
|
|
360 (goto-char w3-scratch-start-point)
|
|
361 (if (and (memq (preceding-char) '(? ?\t ?\r ?\n))
|
|
362 (looking-at "[ \t\r\n]"))
|
|
363 (delete-region (point)
|
|
364 (progn
|
|
365 (skip-chars-forward " \t\r\n")
|
|
366 (point)))))
|
|
367 (goto-char (point-max))
|
|
368 (add-text-properties w3-scratch-start-point
|
20
|
369 (point) (list 'face w3-active-faces
|
|
370 'start-open t
|
|
371 'end-open t
|
|
372 'rear-nonsticky t
|
22
|
373 'duplicable t))
|
14
|
374 (if (car w3-active-voices)
|
|
375 (add-text-properties w3-scratch-start-point (point)
|
|
376 (list 'personality (car w3-active-voices))))
|
|
377 )
|
|
378
|
16
|
379 (defun w3-display-get-cookie (args)
|
|
380 (if (not (fboundp 'cookie))
|
|
381 "Sorry, no cookies today."
|
|
382 (let* ((href (or (w3-get-attribute 'href) (w3-get-attribute 'src)))
|
|
383 (fname (or (cdr-safe (assoc href w3-cookie-cache))
|
|
384 (url-generate-unique-filename "%s.cki")))
|
|
385 (st (or (cdr-safe (assq 'start args)) "Loading cookies..."))
|
|
386 (nd (or (cdr-safe (assq 'end args)) "Loading cookies... done.")))
|
|
387 (if (not (file-exists-p fname))
|
|
388 (save-excursion
|
|
389 (set-buffer (generate-new-buffer " *cookie*"))
|
|
390 (url-insert-file-contents href)
|
|
391 (write-region (point-min) (point-max) fname 5)
|
|
392 (setq w3-cookie-cache (cons (cons href fname) w3-cookie-cache))))
|
|
393 (cookie fname st nd))))
|
|
394
|
14
|
395 (defun w3-widget-echo (widget &rest ignore)
|
16
|
396 (let ((url (widget-get widget 'href))
|
14
|
397 (name (widget-get widget 'name))
|
|
398 (text (buffer-substring (widget-get widget :from)
|
|
399 (widget-get widget :to)))
|
|
400 (title (widget-get widget 'title))
|
16
|
401 (check w3-echo-link)
|
14
|
402 (msg nil))
|
16
|
403 (if url
|
|
404 (setq url (url-truncate-url-for-viewing url)))
|
14
|
405 (if name
|
|
406 (setq name (concat "anchor:" name)))
|
16
|
407 (if (not (listp check))
|
|
408 (setq check (cons check '(title url text name))))
|
|
409 (catch 'exit
|
|
410 (while check
|
|
411 (and (boundp (car check))
|
|
412 (stringp (symbol-value (car check)))
|
|
413 (throw 'exit (symbol-value (car check))))
|
|
414 (pop check)))))
|
14
|
415
|
|
416 (defun w3-follow-hyperlink (widget &rest ignore)
|
|
417 (let* ((target (widget-get widget 'target))
|
|
418 (href (widget-get widget 'href)))
|
|
419 (if target (setq target (intern (downcase target))))
|
|
420 (case target
|
|
421 ((_blank external)
|
|
422 (w3-fetch-other-frame href))
|
|
423 (_top
|
|
424 (delete-other-windows)
|
|
425 (w3-fetch href))
|
|
426 (otherwise
|
|
427 (w3-fetch href)))))
|
|
428
|
|
429 (defun w3-balloon-help-callback (object &optional event)
|
|
430 (let* ((widget (widget-at (extent-start-position object)))
|
|
431 (href (and widget (widget-get widget 'href))))
|
|
432 (if href
|
|
433 (url-truncate-url-for-viewing href)
|
|
434 nil)))
|
|
435
|
|
436
|
|
437 ;; Various macros
|
|
438 (eval-when-compile
|
|
439 (defmacro w3-expand-url (url)
|
|
440 (`
|
|
441 (url-expand-file-name (, url)
|
|
442 (cdr-safe
|
|
443 (assoc
|
|
444 (cdr-safe
|
|
445 (assq 'base args)) w3-base-alist)))))
|
|
446
|
|
447 (defmacro w3-handle-empty-tag ()
|
|
448 (`
|
|
449 (progn
|
|
450 (push (cons tag args) w3-display-open-element-stack)
|
|
451 (push content content-stack)
|
|
452 (setq content nil))))
|
|
453
|
|
454 (defmacro w3-handle-content (node)
|
|
455 (`
|
|
456 (progn
|
|
457 (push (cons tag args) w3-display-open-element-stack)
|
|
458 (push content content-stack)
|
24
|
459 (setq content (nth 2 (, node))))))
|
14
|
460
|
|
461 (defmacro w3-display-handle-list-type ()
|
|
462 (`
|
|
463 (case (car break-style)
|
|
464 (list-item
|
16
|
465 (let ((list-style (w3-get-style-info 'list-style-type node))
|
14
|
466 (list-num (if (car w3-display-list-stack)
|
|
467 (incf (car w3-display-list-stack))
|
|
468 1))
|
|
469 (margin (1- (car left-margin-stack)))
|
|
470 (indent (w3-get-style-info 'text-indent node 0)))
|
|
471 (if (> indent 0)
|
|
472 (setq margin (+ margin indent))
|
|
473 (setq margin (max 0 (- margin indent))))
|
|
474 (beginning-of-line)
|
|
475 (case list-style
|
|
476 ((disc circle square)
|
|
477 (insert (format (format "%%%dc" margin)
|
|
478 (or (cdr-safe (assq list-style w3-bullets))
|
|
479 ?o))))
|
|
480 ((decimal lower-roman upper-roman lower-alpha upper-alpha)
|
|
481 (let ((x (case list-style
|
|
482 (lower-roman
|
|
483 (w3-decimal-to-roman list-num))
|
|
484 (upper-roman
|
|
485 (upcase
|
|
486 (w3-decimal-to-roman list-num)))
|
|
487 (lower-alpha
|
|
488 (w3-decimal-to-alpha list-num))
|
|
489 (upper-alpha
|
|
490 (upcase
|
|
491 (w3-decimal-to-alpha list-num)))
|
|
492 (otherwise
|
|
493 (int-to-string list-num)))))
|
|
494 (insert (format (format "%%%ds." margin) x))
|
|
495 )
|
|
496 )
|
|
497 (otherwise
|
|
498 (insert (w3-get-pad-string margin)))
|
|
499 )
|
|
500 )
|
|
501 )
|
|
502 (otherwise
|
|
503 (insert (w3-get-pad-string (+ (car left-margin-stack)
|
|
504 (w3-get-style-info 'text-indent node 0)))))
|
|
505 )
|
|
506 )
|
|
507 )
|
|
508
|
|
509 (defmacro w3-display-set-margins ()
|
|
510 (`
|
|
511 (progn
|
|
512 (push (+ (w3-get-style-info 'margin-left node 0)
|
|
513 (car left-margin-stack)) left-margin-stack)
|
|
514 (push (-
|
|
515 (car right-margin-stack)
|
|
516 (w3-get-style-info 'margin-right node 0)) right-margin-stack)
|
|
517 (setq fill-column (car right-margin-stack))
|
|
518 (w3-set-fill-prefix-length (car left-margin-stack))
|
|
519 (w3-display-handle-list-type))))
|
|
520
|
|
521 (defmacro w3-display-restore-margins ()
|
|
522 (`
|
|
523 (progn
|
|
524 (pop right-margin-stack)
|
|
525 (pop left-margin-stack))))
|
|
526
|
|
527 (defmacro w3-display-handle-break ()
|
|
528 (`
|
|
529 (case (car break-style)
|
|
530 (block ; Full paragraph break
|
|
531 (if (eq (cadr break-style) 'list-item)
|
|
532 (setf (cadr break-style) 'line)
|
|
533 (w3-display-line-break 1))
|
|
534 (w3-display-set-margins)
|
|
535 (push
|
|
536 (w3-get-style-info 'white-space node
|
|
537 (car w3-display-whitespace-stack))
|
|
538 w3-display-whitespace-stack)
|
|
539 (push
|
|
540 (or (w3-get-attribute 'align)
|
|
541 (w3-get-style-info 'text-align node
|
|
542 (car w3-display-alignment-stack)))
|
|
543 w3-display-alignment-stack)
|
|
544 (and w3-do-incremental-display (w3-pause)))
|
|
545 ((line list-item) ; Single line break
|
|
546 (w3-display-line-break 0)
|
|
547 (w3-display-set-margins)
|
|
548 (push
|
|
549 (w3-get-style-info 'white-space node
|
|
550 (car w3-display-whitespace-stack))
|
|
551 w3-display-whitespace-stack)
|
|
552 (push
|
|
553 (w3-get-style-info 'text-align node
|
|
554 (or (w3-get-attribute 'align)
|
|
555 (car w3-display-alignment-stack)))
|
|
556 w3-display-alignment-stack))
|
|
557 (otherwise ; Assume 'inline' rendering as default
|
|
558 nil))
|
|
559 )
|
|
560 )
|
|
561
|
24
|
562 (defmacro w3-display-progress-meter ()
|
|
563 (`
|
|
564 (url-lazy-message "Drawing... %c" (aref "/|\\-" (random 4)))))
|
|
565
|
14
|
566 (defmacro w3-display-handle-end-break ()
|
|
567 (`
|
|
568 (case (pop break-style)
|
|
569 (block ; Full paragraph break
|
|
570 (w3-display-line-break 1)
|
|
571 (w3-display-restore-margins)
|
|
572 (pop w3-display-whitespace-stack)
|
|
573 (pop w3-display-alignment-stack)
|
|
574 (and w3-do-incremental-display (w3-pause)))
|
|
575 ((line list-item) ; Single line break
|
|
576 (w3-display-restore-margins)
|
|
577 (w3-display-line-break 0)
|
|
578 (pop w3-display-whitespace-stack)
|
|
579 (pop w3-display-alignment-stack))
|
|
580 (otherwise ; Assume 'inline' rendering as default
|
|
581 nil))
|
|
582 )
|
|
583 )
|
|
584 )
|
|
585
|
|
586 ;; <link> handling
|
|
587 (defun w3-parse-link (args)
|
|
588 (let* ((type (if (w3-get-attribute 'rel) 'rel 'rev))
|
|
589 (desc (w3-get-attribute type))
|
|
590 (dc-desc (and desc (downcase desc))) ; canonical case
|
|
591 (dest (w3-get-attribute 'href))
|
|
592 (plist (alist-to-plist args))
|
|
593 (node-1 (assq type w3-current-links))
|
|
594 (node-2 (and node-1 desc (or (assoc desc
|
|
595 (cdr node-1))
|
|
596 (assoc dc-desc
|
|
597 (cdr node-1)))))
|
|
598 )
|
|
599 ;; Canonicalize the case of link types we may look for
|
|
600 ;; specifically (toolbar etc.) since that's done with
|
|
601 ;; assoc. See `w3-mail-document-author' and
|
|
602 ;; `w3-link-toolbar', at least.
|
|
603 (if (member dc-desc w3-defined-link-types)
|
|
604 (setq desc dc-desc))
|
|
605 (if dest ; ignore if HREF missing
|
|
606 (cond
|
|
607 (node-2 ; Add to old value
|
|
608 (setcdr node-2 (cons plist (cdr node-2))))
|
|
609 (node-1 ; first rel/rev
|
|
610 (setcdr node-1 (cons (cons desc (list plist))
|
|
611 (cdr node-1))))
|
|
612 (t (setq w3-current-links
|
|
613 (cons (cons type (list (cons desc (list plist))))
|
|
614 w3-current-links)))))
|
|
615 (setq desc (and desc (intern dc-desc)))
|
|
616 (case desc
|
|
617 ((style stylesheet)
|
16
|
618 (w3-handle-style plist))
|
14
|
619 (otherwise
|
|
620 )
|
|
621 )
|
|
622 )
|
|
623 )
|
|
624
|
|
625
|
|
626 ;; Image handling
|
|
627 (defun w3-maybe-start-image-download (widget)
|
|
628 (let* ((src (widget-get widget 'src))
|
|
629 (cached-glyph (w3-image-cached-p src)))
|
20
|
630 (cond
|
|
631 ((and cached-glyph
|
|
632 (widget-glyphp cached-glyph)
|
|
633 (not (eq 'nothing
|
|
634 (image-instance-type
|
|
635 (glyph-image-instance cached-glyph)))))
|
|
636 (setq w3-image-widgets-waiting (cons widget w3-image-widgets-waiting)))
|
|
637 ((or w3-delay-image-loads ; Delaying images
|
|
638 (not (fboundp 'valid-specifier-domain-p)) ; Can't do images
|
|
639 (eq (device-type) 'tty)) ; Why bother?
|
|
640 (w3-add-delayed-graphic widget))
|
|
641 ((not (w3-image-loadable-p src nil)) ; Hey, we can't load it!
|
22
|
642 (message "Skipping image %s" (url-basepath src t))
|
20
|
643 (w3-add-delayed-graphic widget))
|
|
644 (t ; Grab the images
|
|
645 (let (
|
|
646 (url-request-method "GET")
|
|
647 (old-asynch url-be-asynchronous)
|
|
648 (url-request-data nil)
|
|
649 (url-request-extra-headers nil)
|
|
650 (url-source t)
|
|
651 (url-mime-accept-string (substring
|
|
652 (mapconcat
|
|
653 (function
|
|
654 (lambda (x)
|
|
655 (if x
|
|
656 (concat (car x) ",")
|
|
657 "")))
|
|
658 w3-allowed-image-types "")
|
|
659 0 -1))
|
|
660 (url-working-buffer (generate-new-buffer-name " *W3GRAPH*")))
|
|
661 (setq-default url-be-asynchronous t)
|
|
662 (setq w3-graphics-list (cons (cons src (make-glyph))
|
|
663 w3-graphics-list))
|
|
664 (save-excursion
|
|
665 (set-buffer (get-buffer-create url-working-buffer))
|
|
666 (setq url-current-callback-data (list widget)
|
|
667 url-be-asynchronous t
|
|
668 url-current-callback-func 'w3-finalize-image-download)
|
|
669 (url-retrieve src))
|
|
670 (setq-default url-be-asynchronous old-asynch))))))
|
14
|
671
|
|
672 (defun w3-finalize-image-download (widget)
|
|
673 (let ((glyph nil)
|
|
674 (url (widget-get widget 'src))
|
|
675 (node nil)
|
|
676 (buffer (widget-get widget 'buffer)))
|
|
677 (message "Enhancing image...")
|
|
678 (setq glyph (image-normalize (cdr-safe (assoc url-current-mime-type
|
|
679 w3-image-mappings))
|
|
680 (buffer-string)))
|
|
681 (message "Enhancing image... done")
|
|
682 (kill-buffer (current-buffer))
|
|
683 (cond
|
|
684 ((w3-image-invalid-glyph-p glyph)
|
|
685 (setq glyph nil)
|
22
|
686 (message "Reading of %s failed." url))
|
14
|
687 ((eq (aref glyph 0) 'xbm)
|
|
688 (let ((temp-fname (url-generate-unique-filename "%s.xbm")))
|
|
689 (save-excursion
|
|
690 (set-buffer (generate-new-buffer " *xbm-garbage*"))
|
|
691 (erase-buffer)
|
|
692 (insert (aref glyph 2))
|
|
693 (setq glyph temp-fname)
|
|
694 (write-region (point-min) (point-max) temp-fname)
|
|
695 (kill-buffer (current-buffer)))
|
|
696 (setq glyph (make-glyph (list (cons 'x glyph))))
|
|
697 (condition-case ()
|
|
698 (delete-file temp-fname)
|
|
699 (error nil))))
|
|
700 (t
|
|
701 (setq glyph (make-glyph glyph))))
|
|
702 (setq node (assoc url w3-graphics-list))
|
|
703 (cond
|
|
704 ((and node glyph)
|
|
705 (set-glyph-image (cdr node) (glyph-image glyph)))
|
|
706 (glyph
|
|
707 (setq w3-graphics-list (cons (cons url glyph) w3-graphics-list)))
|
|
708 (t nil))
|
|
709
|
|
710 (if (and (buffer-name buffer) ; Dest. buffer exists
|
|
711 (widget-glyphp glyph)) ; got a valid glyph
|
|
712 (save-excursion
|
|
713 (set-buffer buffer)
|
|
714 (if (eq major-mode 'w3-mode)
|
|
715 (widget-value-set widget glyph)
|
|
716 (setq w3-image-widgets-waiting
|
|
717 (cons widget w3-image-widgets-waiting)))))))
|
|
718
|
|
719 (defmacro w3-node-visible-p ()
|
|
720 (` (not (eq (car break-style) 'none))))
|
|
721
|
|
722 (defmacro w3-handle-image ()
|
|
723 (`
|
|
724 (let* ((height (w3-get-attribute 'height))
|
|
725 (width (w3-get-attribute 'width))
|
|
726 (src (or (w3-get-attribute 'src) "Error Image"))
|
|
727 (our-alt (cond
|
|
728 ((null w3-auto-image-alt) "")
|
|
729 ((eq t w3-auto-image-alt)
|
|
730 (concat "[IMAGE(" (url-basepath src t) ")] "))
|
|
731 ((stringp w3-auto-image-alt)
|
|
732 (format w3-auto-image-alt (url-basepath src t)))))
|
|
733 (alt (or (w3-get-attribute 'alt) our-alt))
|
|
734 (ismap (and (assq 'ismap args) 'ismap))
|
|
735 (usemap (w3-get-attribute 'usemap))
|
|
736 (base (w3-get-attribute 'base))
|
|
737 (href (and hyperlink-info (widget-get (cadr hyperlink-info) 'href)))
|
|
738 (widget nil)
|
|
739 (align (or (w3-get-attribute 'align)
|
|
740 (w3-get-style-info 'vertical-align node))))
|
16
|
741 (if (assq '*table-autolayout w3-display-open-element-stack)
|
|
742 (insert alt)
|
|
743 (setq widget (widget-create 'image
|
|
744 :value-face w3-active-faces
|
|
745 'src src ; Where to load the image from
|
|
746 'alt alt ; Textual replacement
|
|
747 'ismap ismap ; Is it a server-side map?
|
|
748 'usemap usemap ; Is it a client-side map?
|
|
749 'href href ; Hyperlink destination
|
|
750 ))
|
|
751 (widget-put widget 'buffer (current-buffer))
|
|
752 (w3-maybe-start-image-download widget)
|
|
753 (goto-char (point-max))))))
|
14
|
754
|
|
755 ;; The table handling
|
|
756
|
|
757 (defvar w3-display-table-cut-words-p nil
|
|
758 "*Whether to cut words that are oversized in table cells")
|
|
759
|
|
760 (defvar w3-display-table-force-borders nil
|
|
761 "*Whether to always draw table borders")
|
|
762
|
|
763 (defun w3-display-table-cut ()
|
|
764 (save-excursion
|
|
765 (goto-char (point-min))
|
|
766 (let ((offset -1))
|
|
767 (while (< offset 0)
|
|
768 (end-of-line)
|
|
769 (setq offset (- fill-column (current-column)))
|
|
770 (cond ((< offset 0)
|
|
771 (condition-case nil
|
|
772 (progn (forward-char offset)
|
|
773 (insert ?\n))
|
|
774 (error (setq offset 0))))
|
|
775 ((not (eobp))
|
|
776 (forward-line 1)
|
|
777 (setq offset -1)))))))
|
|
778
|
|
779
|
|
780 (defun w3-display-fix-widgets ()
|
|
781 ;; Make markers belong to the right buffer
|
|
782 (save-excursion
|
|
783 (let ((st (point-min))
|
|
784 (nd nil)
|
|
785 (widget nil) parent
|
|
786 (to-marker nil)
|
|
787 (from-marker nil))
|
|
788 (while (setq st (next-single-property-change st 'button))
|
|
789 (setq nd (or (next-single-property-change st 'button) (point-max))
|
|
790 widget (widget-at st)
|
|
791 to-marker (and widget (widget-get widget :to))
|
|
792 from-marker (and widget (widget-get widget :from))
|
|
793 parent (and widget (widget-get widget :parent))
|
|
794 )
|
|
795 (if (not widget)
|
|
796 nil
|
|
797 (widget-put widget :from (set-marker (make-marker) st))
|
|
798 (widget-put widget :to (set-marker (make-marker) nd))
|
|
799 (if (not parent)
|
|
800 nil
|
|
801 (widget-put parent :from (set-marker (make-marker) st))
|
|
802 (widget-put parent :to (set-marker (make-marker) nd))))
|
|
803 (if (condition-case ()
|
|
804 (get-text-property (1+ nd) 'button)
|
|
805 (error nil))
|
|
806 (setq st nd)
|
|
807 (setq st (min (point-max) (1+ nd))))))))
|
|
808
|
|
809 (defun w3-size-of-tree (tree minmax)
|
20
|
810 (declare (special args))
|
14
|
811 (save-excursion
|
|
812 (save-restriction
|
|
813 (narrow-to-region (point) (point))
|
|
814 ;; XXX fill-column set to 1 fails when fill-prefix is set
|
|
815 ;; XXX setting fill-column at all isn't really right
|
|
816 ;; for example <hr>s shouldn't be especially wide
|
|
817 ;; we should set a flag that makes w3 never wrap a line
|
|
818 (let ((fill-column (cond ((eq minmax 'min)
|
|
819 3)
|
|
820 ((eq minmax 'max)
|
|
821 400)))
|
|
822 (fill-prefix "")
|
|
823 (w3-last-fill-pos (point-min))
|
|
824 a retval
|
|
825 (w3-do-incremental-display nil)
|
|
826 (hr-regexp (concat "^"
|
|
827 (regexp-quote
|
|
828 (make-string 5 w3-horizontal-rule-char))
|
|
829 "*$"))
|
|
830 )
|
|
831 ;;(push 'left w3-display-alignment-stack)
|
|
832 (push (if (eq minmax 'max) 'nowrap) w3-display-whitespace-stack)
|
|
833 (while tree
|
|
834 (push (cons '*td args) w3-display-open-element-stack)
|
|
835 (w3-display-node (pop tree)))
|
|
836 (pop w3-display-whitespace-stack)
|
|
837 (goto-char (point-min))
|
|
838 (while (re-search-forward hr-regexp nil t)
|
|
839 (replace-match "" t t))
|
|
840 (goto-char (point-min))
|
|
841 (while (not (eobp))
|
|
842 ;; loop invariant: at beginning of uncounted line
|
|
843 (end-of-line)
|
|
844 (skip-chars-backward " ")
|
|
845 (setq retval (cons (current-column)
|
|
846 retval))
|
|
847 (beginning-of-line 2))
|
|
848 (if (= (point-min) (point-max))
|
|
849 (setq retval 0)
|
|
850 (setq retval (apply 'max (cons 0 retval))))
|
|
851 (delete-region (point-min) (point-max))
|
|
852 retval))))
|
|
853
|
|
854 (defun w3-display-table-dimensions (node)
|
|
855 ;; fill-column sets maximum width
|
20
|
856 (declare (special args))
|
14
|
857 (let (min-vector
|
|
858 max-vector
|
|
859 rows cols
|
|
860 ;;(w3-form-elements (and (boundp 'w3-form-elements) w3-form-elements))
|
|
861 (table-info (assq 'w3-table-info (cadr node))))
|
|
862
|
|
863 (if table-info
|
|
864 (setq min-vector (nth 1 table-info)
|
|
865 max-vector (nth 2 table-info)
|
|
866 rows (nth 3 table-info)
|
|
867 cols (nth 4 table-info))
|
|
868
|
|
869 (push (cons '*table-autolayout args) w3-display-open-element-stack)
|
|
870 (let (content
|
|
871 cur
|
|
872 (table-spans (list nil)) ; don't make this '(nil)
|
|
873 ptr
|
|
874 col
|
|
875 constraints
|
|
876
|
|
877 colspan rowspan min max)
|
|
878 (setq content (nth 2 node))
|
|
879 (setq rows 0 cols 0)
|
|
880 (while content
|
|
881 (setq cur (pop content))
|
|
882 (if (stringp cur)
|
|
883 nil
|
|
884 (case (car cur)
|
|
885 (tr
|
|
886 (setq col 0)
|
|
887 (setq rows (1+ rows))
|
|
888 (setq ptr table-spans)
|
|
889 (mapcar
|
|
890 (function
|
|
891 (lambda (td)
|
|
892 (setq colspan (string-to-int (or (cdr-safe (assq 'colspan (nth 1 td))) "1"))
|
|
893 rowspan (string-to-int (or (cdr-safe (assq 'rowspan (nth 1 td))) "1"))
|
|
894 min (w3-size-of-tree (nth 2 td) 'min)
|
|
895 max (w3-size-of-tree (nth 2 td) 'max)
|
|
896 )
|
|
897 (while (eq (car-safe (car-safe (cdr ptr))) col)
|
|
898 (setq col (+ col (cdr (cdr (car (cdr ptr))))))
|
|
899 (if (= 0 (decf (car (cdr (car (cdr ptr))))))
|
|
900 (pop (cdr ptr))
|
|
901 (setq ptr (cdr ptr))))
|
|
902 (push (list col colspan min max)
|
|
903 constraints)
|
|
904 (if (= rowspan 1) nil
|
|
905 (push (cons col (cons (1- rowspan) colspan)) (cdr ptr))
|
|
906 (setq ptr (cdr ptr)))
|
|
907 (setq col (+ col colspan))
|
|
908 ))
|
|
909 (nth 2 cur))
|
|
910 (while (cdr ptr)
|
|
911 (if (= 0 (decf (car (cdr (car (cdr ptr))))))
|
|
912 (pop (cdr ptr))
|
|
913 (setq ptr (cdr ptr))))
|
|
914 (setq cols (max cols col))
|
|
915 )
|
|
916 (caption
|
|
917 nil)
|
|
918 (otherwise
|
|
919 (setq content (nth 2 cur)))
|
|
920 )
|
|
921 )
|
|
922 )
|
|
923 (setq constraints (sort constraints
|
|
924 (function
|
|
925 (lambda (a b)
|
|
926 (< (cadr a) (cadr b)))))
|
|
927 min-vector (make-vector cols 0)
|
|
928 max-vector (make-vector cols 0))
|
|
929 (let (start end i mincellwidth maxcellwidth)
|
|
930 (mapcar (function (lambda (c)
|
|
931 (cond ((= (cadr c) 1)
|
|
932 (aset min-vector (car c)
|
|
933 (max (aref min-vector (car c))
|
|
934 (nth 2 c)))
|
|
935 (aset max-vector (car c)
|
|
936 (max (aref max-vector (car c))
|
|
937 (nth 3 c))))
|
|
938 (t
|
|
939 (setq start (car c)
|
|
940 end (+ (car c) (cadr c))
|
|
941 mincellwidth 0
|
|
942 maxcellwidth 0
|
|
943 i start)
|
|
944 (while (< i end)
|
|
945 (setq mincellwidth (+ mincellwidth
|
|
946 (aref min-vector i))
|
|
947 maxcellwidth (+
|
|
948 maxcellwidth
|
|
949 (aref max-vector i))
|
|
950 i (1+ i)))
|
|
951 (setq i start)
|
|
952 (if (= mincellwidth 0)
|
|
953 ;; if existing width is 0 divide evenly
|
|
954 (while (< i end)
|
|
955 (aset min-vector i
|
|
956 (/ (nth 2 c) (cadr c)))
|
|
957 (aset max-vector i
|
|
958 (/ (nth 3 c) (cadr c)))
|
|
959 (setq i (1+ i)))
|
|
960 ;; otherwise weight it by existing widths
|
|
961 (while (< i end)
|
|
962 (aset min-vector i
|
|
963 (max (aref min-vector i)
|
|
964 (/ (* (nth 2 c)
|
|
965 (aref min-vector i))
|
|
966 mincellwidth)))
|
|
967 (aset max-vector i
|
|
968 (max (aref max-vector i)
|
|
969 (/ (* (nth 3 c)
|
|
970 (aref max-vector i))
|
|
971 maxcellwidth)))
|
|
972 (setq i (1+ i))))
|
|
973 ))))
|
|
974 constraints)))
|
|
975 (push (cons 'w3-table-info
|
|
976 (list min-vector max-vector rows cols))
|
|
977 (cadr node))
|
|
978 (pop w3-display-open-element-stack))
|
|
979
|
|
980 (let (max-width
|
|
981 min-width
|
|
982 ret-vector
|
|
983 col
|
|
984 )
|
|
985
|
|
986
|
|
987 (setq max-width (apply '+ (append max-vector (list cols 1))))
|
|
988 (setq min-width (apply '+ (append min-vector (list cols 1))))
|
|
989
|
|
990 ;; the comments in the cond are excerpts from rfc1942 itself
|
|
991 (cond
|
|
992 ;; 1. The minimum table width is equal to or wider than the available
|
|
993 ;; space. In this case, assign the minimum widths and allow the
|
|
994 ;; user to scroll horizontally. For conversion to braille, it will
|
|
995 ;; be necessary to replace the cells by references to notes
|
|
996 ;; containing their full content. By convention these appear
|
|
997 ;; before the table.
|
|
998 ((>= min-width fill-column)
|
|
999 (setq ret-vector min-vector))
|
|
1000
|
|
1001 ;; 2. The maximum table width fits within the available space. In
|
|
1002 ;; this case, set the columns to their maximum widths.
|
|
1003 ((<= max-width fill-column)
|
|
1004 (setq ret-vector max-vector))
|
|
1005
|
|
1006 ;; 3. The maximum width of the table is greater than the available
|
|
1007 ;; space, but the minimum table width is smaller. In this case,
|
|
1008 ;; find the difference between the available space and the minimum
|
|
1009 ;; table width, lets call it W. Lets also call D the difference
|
|
1010 ;; between maximum and minimum width of the table.
|
|
1011
|
|
1012 ;; For each column, let d be the difference between maximum and
|
|
1013 ;; minimum width of that column. Now set the column's width to the
|
|
1014 ;; minimum width plus d times W over D. This makes columns with
|
|
1015 ;; large differences between minimum and maximum widths wider than
|
|
1016 ;; columns with smaller differences.
|
|
1017 (t
|
|
1018 (setq ret-vector (make-vector cols 0))
|
|
1019 (let ((W (- fill-column min-width))
|
|
1020 (D (- max-width min-width))
|
|
1021 d extra)
|
|
1022 (setq col 0)
|
|
1023 (while (< col (length ret-vector))
|
|
1024 (setq d (- (aref max-vector col)
|
|
1025 (aref min-vector col)))
|
|
1026 (aset ret-vector col
|
|
1027 (+ (aref min-vector col)
|
|
1028 (/ (* d W) D)))
|
|
1029 (setq col (1+ col)))
|
|
1030 (setq extra (- fill-column
|
|
1031 (apply '+ (append ret-vector
|
|
1032 (list (length ret-vector) 1))))
|
|
1033 col 0)
|
|
1034 (while (and (< col (length ret-vector)) (> extra 0))
|
|
1035 (if (= 1 (- (aref max-vector col) (aref ret-vector col) ))
|
|
1036 (aset ret-vector col (1+ (aref ret-vector col))))
|
|
1037 (setq extra (1- extra)
|
|
1038 col (1+ col)))
|
|
1039 )))
|
|
1040 (list rows cols ret-vector))))
|
|
1041
|
|
1042 (defvar w3-table-ascii-border-chars
|
|
1043 [? ? ? ?/ ? ?- ?\\ ?- ? ?\\ ?| ?| ?/ ?- ?| ?-]
|
|
1044 "Vector of ascii characters to use to draw table borders.
|
|
1045 w3-table-unhack-border-chars uses this to restore w3-table-border-chars.")
|
|
1046
|
|
1047 (defvar w3-table-border-chars w3-table-ascii-border-chars
|
|
1048 "Vector of characters to use to draw table borders.
|
|
1049 If you set this you should set w3-table-ascii-border-chars to the same value
|
|
1050 so that w3-table-unhack-borders can restore the value if necessary.
|
|
1051
|
|
1052 A reasonable value is [? ? ? ?/ ? ?- ?\\\\ ?^ ? ?\\\\ ?| ?< ?/ ?- ?> ?-]
|
|
1053 Though i recommend replacing the ^ with - and the < and > with |")
|
|
1054
|
|
1055 (defsubst w3-table-lookup-char (l u r b)
|
|
1056 (aref w3-table-border-chars (logior (if l 1 0)
|
|
1057 (if u 2 0)
|
|
1058 (if r 4 0)
|
|
1059 (if b 8 0))))
|
|
1060
|
|
1061 (defun w3-table-hack-borders nil
|
|
1062 "Try to find the best set of characters to draw table borders with.
|
|
1063 I definitely recommend trying this on X.
|
|
1064 On a console, this can trigger some Emacs display bugs.
|
|
1065
|
|
1066 I haven't tried this on XEmacs or any window-system other than X."
|
|
1067 (interactive)
|
|
1068 (case (device-type)
|
|
1069 (x
|
|
1070 (let ((id (or (and (find-face 'w3-table-hack-x-face)
|
|
1071 (face-id 'w3-table-hack-x-face))
|
|
1072 (progn
|
|
1073 (make-face 'w3-table-hack-x-face)
|
|
1074 (set-face-font 'w3-table-hack-x-face
|
|
1075 (make-font :family "terminal"))
|
|
1076 (face-id 'w3-table-hack-x-face)))))
|
|
1077 (if (not (face-differs-from-default-p 'w3-table-hack-x-face))
|
|
1078 nil
|
|
1079 (aset standard-display-table 1 (vector (+ (* 256 id) ?l)))
|
|
1080 (aset standard-display-table 2 (vector (+ (* 256 id) ?q)))
|
|
1081 (aset standard-display-table 3 (vector (+ (* 256 id) ?k)))
|
|
1082 (aset standard-display-table 4 (vector (+ (* 256 id) ?t)))
|
|
1083 (aset standard-display-table 5 (vector (+ (* 256 id) ?n)))
|
|
1084 (aset standard-display-table 6 (vector (+ (* 256 id) ?u)))
|
|
1085 (aset standard-display-table 7 (vector (+ (* 256 id) ?m)))
|
|
1086 (aset standard-display-table 8 (vector (+ (* 256 id) ?x)))
|
|
1087 (aset standard-display-table 11 (vector (+ (* 256 id) ?j)))
|
|
1088 (aset standard-display-table 14 (vector (+ (* 256 id) ?v)))
|
|
1089 (aset standard-display-table 15 (vector (+ (* 256 id) ?w)))
|
|
1090 (setq w3-table-border-chars [? ? ? 11 ? 2 7 14 ? 3 8 6 1 15 4 5])
|
|
1091 (setq w3-horizontal-rule-char 2))))
|
|
1092 (tty
|
|
1093 (standard-display-g1 1 108) ; ulcorner
|
|
1094 (standard-display-g1 2 113) ; hline
|
|
1095 (standard-display-g1 3 107) ; urcorner
|
|
1096 (standard-display-g1 4 116) ; leftt
|
|
1097 (standard-display-g1 5 110) ; intersection
|
|
1098 (standard-display-g1 6 117) ; rightt
|
|
1099 (standard-display-g1 7 109) ; llcorner
|
|
1100 (standard-display-g1 8 120) ; vline
|
|
1101 (standard-display-g1 11 106) ; lrcorner
|
|
1102 (standard-display-g1 14 118) ; upt
|
|
1103 (standard-display-g1 15 119) ; downt
|
|
1104 (setq w3-table-border-chars [? ? ? 11 ? 2 7 14 ? 3 8 6 1 15 4 5])
|
|
1105 (setq w3-horizontal-rule-char 2))
|
|
1106 (otherwise
|
|
1107 (error "Unknown window-system, can't do any better than ascii borders")))
|
|
1108 )
|
|
1109
|
|
1110 (defun w3-table-unhack-borders nil
|
|
1111 (interactive)
|
|
1112 (w3-table-excise-hack (buffer-list))
|
|
1113 (standard-display-default 1 15)
|
|
1114 (setq w3-table-border-chars w3-table-ascii-border-chars)
|
|
1115 (setq w3-horizontal-rule-char ?-))
|
|
1116
|
|
1117 (defun w3-table-excise-hack (buffs)
|
|
1118 "Replace hacked characters with ascii characters in buffers BUFFS.
|
|
1119 Should be run before restoring w3-table-border-chars to ascii characters."
|
|
1120 (interactive (list (list (current-buffer))))
|
|
1121 (let ((inhibit-read-only t)
|
|
1122 (tr (make-string 16 ? ))
|
|
1123 (i 0))
|
|
1124 (while (< i (length tr))
|
|
1125 (aset tr i i)
|
|
1126 (setq i (1+ i)))
|
|
1127 (setq i 0)
|
|
1128 (while (< i (length w3-table-border-chars))
|
|
1129 (if (< (aref w3-table-border-chars i) 16)
|
|
1130 (aset tr
|
|
1131 (aref w3-table-border-chars i)
|
|
1132 (aref w3-table-ascii-border-chars i)))
|
|
1133 (setq i (1+ i)))
|
|
1134 (mapcar (function (lambda (buf)
|
|
1135 (save-excursion
|
|
1136 (set-buffer buf)
|
|
1137 (if (eq major-mode 'w3-mode)
|
|
1138 (translate-region (point-min)
|
|
1139 (point-max)
|
|
1140 tr)))))
|
|
1141 buffs)))
|
|
1142
|
|
1143 (defun w3-display-table (node)
|
|
1144 (let* ((dimensions (w3-display-table-dimensions node))
|
|
1145 (num-cols (max (cadr dimensions) 1))
|
|
1146 (num-rows (max (car dimensions) 1))
|
|
1147 (column-dimensions (caddr dimensions))
|
|
1148 (table-width (apply '+ (append column-dimensions (list num-cols 1)))))
|
|
1149 (cond
|
|
1150 ((or (<= (cadr dimensions) 0) (<= (car dimensions) 0))
|
|
1151 ;; We have an invalid table
|
|
1152 nil)
|
|
1153 ((assq '*table-autolayout w3-display-open-element-stack)
|
|
1154 ;; don't bother displaying the table if all we really need is the size
|
|
1155 (progn (insert-char ?T table-width) (insert "\n")))
|
|
1156 (t
|
|
1157 (let* ((tag (nth 0 node))
|
|
1158 (args (nth 1 node))
|
|
1159 (border-node (cdr-safe (assq 'border args)))
|
|
1160 (border (or w3-display-table-force-borders
|
|
1161 (and border-node
|
|
1162 (or (/= 0 (string-to-int border-node))
|
|
1163 (string= "border" border-node)))))
|
|
1164 (w3-table-border-chars
|
|
1165 (if border
|
|
1166 w3-table-border-chars
|
|
1167 (make-vector (length w3-table-border-chars) ? )))
|
|
1168 valign align
|
|
1169 (content (nth 2 node))
|
|
1170 (avgwidth (/ (- fill-column num-cols num-cols) num-cols))
|
|
1171 (formatted-cols (make-vector num-cols nil))
|
|
1172 (table-rowspans (make-vector num-cols 0))
|
|
1173 (table-colspans (make-vector num-cols 1))
|
|
1174 (prev-colspans (make-vector num-cols 0))
|
|
1175 (prev-rowspans (make-vector num-cols 0))
|
|
1176 (table-colwidth (make-vector num-cols 0))
|
|
1177 (fill-prefix "")
|
|
1178 (height nil)
|
|
1179 (cur-height nil)
|
|
1180 (cols nil)
|
|
1181 (rows nil)
|
|
1182 (row 0)
|
|
1183 (this-rectangle nil)
|
|
1184 (i 0)
|
|
1185 )
|
|
1186
|
|
1187 (push (cons tag args) w3-display-open-element-stack)
|
|
1188
|
|
1189 (if (memq 'nowrap w3-display-whitespace-stack)
|
|
1190 (setq fill-prefix "")
|
|
1191 (case (car w3-display-alignment-stack)
|
|
1192 (center
|
|
1193 (w3-set-fill-prefix-length
|
|
1194 (max 0 (/ (- fill-column table-width) 2))))
|
|
1195 (right
|
|
1196 (w3-set-fill-prefix-length
|
|
1197 (max 0 (- fill-column table-width))))
|
|
1198 (t
|
|
1199 (setq fill-prefix ""))))
|
|
1200 (while content
|
|
1201 (case (caar content)
|
|
1202 (tr
|
|
1203 (setq w3-display-css-properties (css-get
|
|
1204 (nth 0 (car content))
|
|
1205 (nth 1 (car content))
|
|
1206 w3-current-stylesheet
|
|
1207 w3-display-open-element-stack))
|
|
1208 (setq cols (nth 2 (car content))
|
|
1209 valign (or (cdr-safe (assq 'valign (nth 1 (car content))))
|
|
1210 (w3-get-style-info 'vertical-align node))
|
|
1211 align (or (cdr-safe (assq 'align (nth 1 (car content))))
|
|
1212 (w3-get-style-info 'text-align node))
|
|
1213 content (cdr content)
|
|
1214 row (1+ row))
|
|
1215 (if (and valign (stringp valign))
|
|
1216 (setq valign (intern (downcase valign))))
|
|
1217 ;; this is iffy
|
|
1218 ;;(if align (push (intern (downcase align)) w3-display-alignment-stack))
|
|
1219 (save-excursion
|
|
1220 (save-restriction
|
|
1221 (narrow-to-region (point) (point))
|
|
1222 (setq fill-column avgwidth
|
24
|
1223 inhibit-read-only t
|
14
|
1224 w3-last-fill-pos (point-min)
|
|
1225 i 0)
|
|
1226 ;; skip over columns that have leftover content
|
|
1227 (while (and (< i num-cols)
|
|
1228 (/= 0 (aref table-rowspans i)))
|
|
1229 (setq i (+ i (max 1 (aref table-colspans i)))))
|
|
1230 (while cols
|
|
1231 (let* ((node (car cols))
|
|
1232 (attributes (nth 1 node))
|
|
1233 (colspan (string-to-int
|
|
1234 (or (cdr-safe (assq 'colspan attributes))
|
|
1235 "1")))
|
|
1236 (rowspan (string-to-int
|
|
1237 (or (cdr-safe (assq 'rowspan attributes))
|
|
1238 "1")))
|
|
1239 fill-column column-width
|
|
1240 (fill-prefix "")
|
|
1241 (w3-do-incremental-display nil)
|
|
1242 (indent-tabs-mode nil)
|
|
1243 c e
|
|
1244 )
|
|
1245
|
|
1246 (aset table-colspans i colspan)
|
|
1247 (aset table-rowspans i rowspan)
|
|
1248
|
|
1249 (setq fill-column 0)
|
|
1250 (setq c i
|
|
1251 e (+ i colspan))
|
|
1252 (while (< c e)
|
|
1253 (setq fill-column (+ fill-column
|
|
1254 (aref column-dimensions c)
|
|
1255 1)
|
|
1256 c (1+ c)))
|
|
1257 (setq fill-column (1- fill-column))
|
|
1258 (aset table-colwidth i fill-column)
|
|
1259
|
|
1260 (setq w3-last-fill-pos (point-min))
|
|
1261 (push (cons (nth 0 node) (nth 1 node))
|
|
1262 w3-display-open-element-stack)
|
|
1263 (w3-display-node node)
|
|
1264 (setq fill-column (aref table-colwidth i))
|
|
1265 (if w3-display-table-cut-words-p
|
|
1266 (w3-display-table-cut))
|
|
1267 (setq cols (cdr cols))
|
|
1268 (goto-char (point-min))
|
|
1269 (skip-chars-forward "\t\n\r")
|
|
1270 (beginning-of-line)
|
|
1271 (delete-region (point-min) (point))
|
|
1272 (goto-char (point-max))
|
|
1273 (skip-chars-backward " \t\n\r")
|
|
1274 (delete-region (point) (point-max))
|
|
1275 (if (>= fill-column (current-column))
|
|
1276 (insert-char ? (- fill-column (current-column))))
|
|
1277 (aset formatted-cols i (extract-rectangle (point-min) (point-max)))
|
|
1278 (delete-region (point-min) (point-max))
|
|
1279 (let ((j (1- colspan)))
|
|
1280 (while (> j 0)
|
|
1281 (aset table-colspans (+ i j) 0)
|
|
1282 (setq j (1- j))))
|
|
1283 (setq i (+ i colspan))
|
|
1284 ;; skip over columns that have leftover content
|
|
1285 (while (and (< i num-cols)
|
|
1286 (/= 0 (aref table-rowspans i)))
|
|
1287 (setq i (+ i (max 1 (aref table-colspans i)))))
|
|
1288 ))
|
|
1289
|
|
1290 ;; finish off the columns
|
|
1291 (while (< i num-cols)
|
|
1292 (aset table-colwidth i (aref column-dimensions i))
|
|
1293 (aset table-colspans i 1)
|
|
1294 (setq i (1+ i))
|
|
1295 (while (and (< i num-cols)
|
|
1296 (/= 0 (aref table-rowspans i)))
|
|
1297 (setq i (+ i (max 1 (aref table-colspans i))))))
|
|
1298
|
|
1299 ;; on the last row empty any pending rowspans per the rfc
|
|
1300 (if content nil
|
|
1301 (fillarray table-rowspans 1))
|
|
1302
|
|
1303 ;; Find the tallest rectangle that isn't a rowspanning cell
|
|
1304 (setq height 0
|
|
1305 i 0)
|
|
1306 (while (< i num-cols)
|
|
1307 (if (= 1 (aref table-rowspans i))
|
|
1308 (setq height (max height (length (aref formatted-cols i)))))
|
|
1309 (setq i (+ i (max 1 (aref table-colspans i)))))
|
|
1310
|
|
1311 ;; Make all rectangles the same height
|
|
1312 (setq i 0)
|
|
1313 (while (< i num-cols)
|
|
1314 (setq this-rectangle (aref formatted-cols i))
|
|
1315 (if (> height (length this-rectangle))
|
|
1316 (let ((colspan-fill-line
|
20
|
1317 (make-string (abs (aref table-colwidth i)) ? )))
|
14
|
1318 (case valign
|
|
1319 ((center middle)
|
|
1320 (aset formatted-cols i
|
|
1321 (append (make-list (/ (- height (length this-rectangle)) 2)
|
|
1322 colspan-fill-line)
|
|
1323 this-rectangle)))
|
|
1324 (bottom
|
|
1325 (aset formatted-cols i
|
|
1326 (append (make-list (- height (length this-rectangle))
|
|
1327 colspan-fill-line)
|
|
1328 this-rectangle))))))
|
|
1329 (setq i (+ i (max 1 (aref table-colspans i)))))))
|
|
1330
|
|
1331
|
|
1332 ;; fix broken colspans (this should only matter on illegal tables)
|
|
1333 (setq i 0)
|
|
1334 (while (< i num-cols)
|
|
1335 (if (= (aref table-colspans i) 0)
|
|
1336 (aset table-colspans i 1))
|
|
1337 (setq i (+ i (aref table-colspans i))))
|
|
1338
|
|
1339 ;; Insert a separator
|
|
1340 (insert fill-prefix)
|
|
1341 (setq i 0)
|
|
1342 (let (rflag bflag tflag lflag)
|
|
1343 (while (< i num-cols)
|
|
1344
|
|
1345 (setq rflag (= (aref prev-rowspans i) 0))
|
|
1346 (setq bflag (/= (aref table-colspans i) 0))
|
|
1347 (setq tflag (/= (aref prev-colspans i) 0))
|
|
1348
|
|
1349 (insert (w3-table-lookup-char lflag tflag rflag bflag))
|
|
1350 (setq lflag t)
|
|
1351 (cond ((= (aref prev-rowspans i) 0)
|
|
1352 (insert-char (w3-table-lookup-char t nil t nil)
|
|
1353 (aref column-dimensions i))
|
|
1354 (setq i (1+ i)))
|
|
1355 ((car (aref formatted-cols i))
|
|
1356 (insert (pop (aref formatted-cols i)))
|
|
1357 (setq lflag nil)
|
|
1358 (setq i (+ i (max (aref table-colspans i)
|
|
1359 (aref prev-colspans i) 1))))
|
|
1360 (t
|
|
1361 (insert-char ? (aref table-colwidth i))
|
|
1362 (setq lflag nil)
|
|
1363 (setq i (+ i (max (aref table-colspans i)
|
|
1364 (aref prev-colspans i) 1))))))
|
|
1365 (insert (w3-table-lookup-char lflag (/= row 1) nil t) "\n"))
|
|
1366
|
|
1367 ;; recalculate height (in case we've shortened a rowspanning cell
|
|
1368 (setq height 0
|
|
1369 i 0)
|
|
1370 (while (< i num-cols)
|
|
1371 (if (= 1 (aref table-rowspans i))
|
|
1372 (setq height (max height (length (aref formatted-cols i)))))
|
|
1373 (setq i (+ i (max 1 (aref table-colspans i)))))
|
|
1374
|
|
1375 ;; Insert a row back in original buffer
|
|
1376 (while (> height 0)
|
|
1377 (insert fill-prefix (w3-table-lookup-char nil t nil t))
|
|
1378 (setq i 0)
|
|
1379 (while (< i num-cols)
|
|
1380 (if (car (aref formatted-cols i))
|
|
1381 (insert (pop (aref formatted-cols i)))
|
|
1382 (insert-char ? (aref table-colwidth i)))
|
|
1383 (insert (w3-table-lookup-char nil t nil t))
|
|
1384 (setq i (+ i (max (aref table-colspans i) 1))))
|
|
1385 (insert "\n")
|
|
1386 ;;(and w3-do-incremental-display (w3-pause))
|
|
1387 (setq height (1- height)))
|
|
1388
|
|
1389 (setq i 0)
|
|
1390 (while (< i num-cols)
|
|
1391 (if (> (aref table-rowspans i) 0)
|
|
1392 (decf (aref table-rowspans i)))
|
|
1393 (incf i))
|
|
1394
|
|
1395 (setq prev-rowspans (copy-seq table-rowspans))
|
|
1396 (setq prev-colspans (copy-seq table-colspans))
|
|
1397
|
|
1398 (and w3-do-incremental-display (w3-pause))
|
|
1399
|
|
1400 )
|
|
1401 (caption
|
|
1402 (let ((left (length fill-prefix))
|
|
1403 (fill-prefix "")
|
|
1404 (fill-column table-width)
|
|
1405 (start (point)))
|
|
1406 (w3-display-node (pop content))
|
|
1407 (indent-rigidly start (point) left)))
|
|
1408 (otherwise
|
|
1409 (delete-horizontal-space)
|
|
1410 (setq content (nth 2 (car content))))
|
|
1411 ))
|
|
1412 (if (= (length column-dimensions) 0) nil
|
|
1413 (insert fill-prefix)
|
|
1414 (setq i 0)
|
|
1415 (let (tflag lflag)
|
|
1416 (while (< i num-cols)
|
|
1417 (setq tflag (/= (aref prev-colspans i) 0))
|
|
1418 (insert (w3-table-lookup-char lflag tflag t nil))
|
|
1419 (setq lflag t)
|
|
1420 (insert-char (w3-table-lookup-char t nil t nil)
|
|
1421 (aref column-dimensions i))
|
|
1422 (setq i (1+ i)))
|
|
1423 (insert (w3-table-lookup-char t t nil nil) "\n")))
|
|
1424 )
|
|
1425 (pop w3-display-open-element-stack)))))
|
|
1426
|
|
1427
|
|
1428
|
|
1429 (defun w3-display-create-unique-id ()
|
|
1430 (let* ((date (current-time-string))
|
|
1431 (dateinfo (and date (timezone-parse-date date)))
|
|
1432 (timeinfo (and date (timezone-parse-time (aref dateinfo 3)))))
|
|
1433 (if (and dateinfo timeinfo)
|
|
1434 (concat (aref dateinfo 0) ; Year
|
|
1435 (aref dateinfo 1) ; Month
|
|
1436 (aref dateinfo 2) ; Day
|
|
1437 (aref timeinfo 0) ; Hour
|
|
1438 (aref timeinfo 1) ; Minute
|
|
1439 (aref timeinfo 2) ; Second
|
|
1440 )
|
|
1441 "HoplesSLYCoNfUSED")))
|
|
1442
|
16
|
1443 (defun w3-display-chop-into-table (node cols)
|
|
1444 ;; Chop the content of 'node' up into 'cols' columns suitable for inclusion
|
|
1445 ;; as the content of a table
|
|
1446 (let ((content (nth 2 node))
|
|
1447 (items nil)
|
|
1448 (rows nil))
|
|
1449 (setq cols (max cols 1))
|
|
1450 (while content
|
|
1451 (push (list 'td nil (list (pop content))) items)
|
|
1452 (if (= (length items) cols)
|
|
1453 (setq rows (cons (nreverse items) rows)
|
|
1454 items nil)))
|
|
1455 (if items ; Store any leftovers
|
|
1456 (setq rows (cons (nreverse items) rows)
|
|
1457 items nil))
|
|
1458 (while rows
|
|
1459 (push (list 'tr nil (pop rows)) items))
|
|
1460 items))
|
|
1461
|
|
1462 (defun w3-display-normalize-form-info (args)
|
|
1463 (let* ((plist (alist-to-plist args))
|
|
1464 (type (intern (downcase
|
|
1465 (or (plist-get plist 'type) "text"))))
|
|
1466 (name (plist-get plist 'name))
|
|
1467 (value (or (plist-get plist 'value) ""))
|
|
1468 (size (if (plist-get plist 'size)
|
|
1469 (string-to-int (plist-get plist 'size))))
|
|
1470 (maxlength (if (plist-get plist 'maxlength)
|
|
1471 (string-to-int
|
|
1472 (plist-get plist 'maxlength))))
|
|
1473 (default value)
|
|
1474 (checked (assq 'checked args)))
|
|
1475 (if (memq type '(checkbox radio)) (setq default checked))
|
|
1476 (if (and (eq type 'checkbox) (string= value ""))
|
|
1477 (setq value "on"))
|
|
1478 (if (and (not (memq type '(submit reset button)))
|
|
1479 (not name))
|
|
1480 (setq name (symbol-name type)))
|
|
1481 (while (and name (string-match "[\r\n]+" name))
|
|
1482 (setq name (concat (substring name 0 (match-beginning 0))
|
|
1483 (substring name (match-end 0) nil))))
|
|
1484 (setq plist (plist-put plist 'type type)
|
|
1485 plist (plist-put plist 'name name)
|
|
1486 plist (plist-put plist 'value value)
|
|
1487 plist (plist-put plist 'size size)
|
|
1488 plist (plist-put plist 'default default)
|
|
1489 plist (plist-put plist 'internal-form-number w3-current-form-number)
|
|
1490 plist (plist-put plist 'action w3-display-form-id)
|
|
1491 plist (plist-put plist 'maxlength maxlength))
|
|
1492 plist))
|
|
1493
|
14
|
1494 (defun w3-display-node (node &optional nofaces)
|
|
1495 (let (
|
|
1496 (content-stack (list (list node)))
|
|
1497 (right-margin-stack (list fill-column))
|
|
1498 (left-margin-stack (list 0))
|
24
|
1499 (inhibit-read-only t)
|
14
|
1500 node
|
|
1501 insert-before
|
|
1502 insert-after
|
|
1503 tag
|
|
1504 args
|
|
1505 content
|
|
1506 hyperlink-info
|
|
1507 break-style
|
|
1508 cur
|
|
1509 id
|
|
1510 class
|
|
1511 )
|
|
1512 (while content-stack
|
|
1513 (setq content (pop content-stack))
|
|
1514 (pop w3-active-faces)
|
|
1515 (pop w3-active-voices)
|
24
|
1516 (w3-display-progress-meter)
|
14
|
1517 (case (car (pop w3-display-open-element-stack))
|
|
1518 ;; Any weird, post-display-of-content stuff for specific tags
|
|
1519 ;; goes here. Couldn't think of any better way to do this when we
|
|
1520 ;; are iterative. *sigh*
|
|
1521 (a
|
|
1522 (if (not hyperlink-info)
|
|
1523 nil
|
|
1524 (add-text-properties (car hyperlink-info) (point)
|
|
1525 (list
|
|
1526 'mouse-face 'highlight
|
|
1527 'duplicable t
|
16
|
1528 'start-open t
|
|
1529 'end-open t
|
|
1530 'rear-nonsticky t
|
14
|
1531 'help-echo 'w3-balloon-help-callback
|
|
1532 'balloon-help 'w3-balloon-help-callback))
|
|
1533 (fillin-text-property (car hyperlink-info) (point)
|
|
1534 'button 'button (cadr hyperlink-info))
|
|
1535 (widget-put (cadr hyperlink-info) :to (set-marker
|
|
1536 (make-marker) (point))))
|
|
1537 (setq hyperlink-info nil))
|
|
1538 ((ol ul dl dir menu)
|
|
1539 (pop w3-display-list-stack))
|
|
1540 (otherwise
|
|
1541 nil))
|
|
1542 (if (car insert-after)
|
|
1543 (w3-handle-string-content (car insert-after)))
|
|
1544 (pop insert-after)
|
|
1545 (w3-display-handle-end-break)
|
|
1546 (w3-pop-all-face-info)
|
|
1547 ;; Handle the element's content
|
|
1548 (while content
|
24
|
1549 (w3-display-progress-meter)
|
14
|
1550 (if (stringp (car content))
|
|
1551 (w3-handle-string-content (pop content))
|
|
1552 (setq node (pop content)
|
|
1553 tag (nth 0 node)
|
|
1554 args (nth 1 node)
|
|
1555 id (or (w3-get-attribute 'name)
|
|
1556 (w3-get-attribute 'id))
|
|
1557 )
|
|
1558 ;; This little bit of magic takes care of inline styles.
|
|
1559 ;; Evil Evil Evil, but it appears to work.
|
|
1560 (if (w3-get-attribute 'style)
|
|
1561 (let ((unique-id (or (w3-get-attribute 'id)
|
|
1562 (w3-display-create-unique-id)))
|
16
|
1563 (sheet "")
|
|
1564 (class (assq 'class args)))
|
14
|
1565 (setq sheet (format "%s.%s { %s }\n" tag unique-id
|
|
1566 (w3-get-attribute 'style)))
|
16
|
1567 (if class
|
|
1568 (setcdr class (cons unique-id (cdr class)))
|
|
1569 (setf (nth 1 node) (cons (cons 'class (list unique-id))
|
|
1570 (nth 1 node))))
|
|
1571 (setf (nth 1 node) (cons (cons 'id unique-id) (nth 1 node)))
|
|
1572 (w3-handle-style (list 'data sheet
|
|
1573 'notation "css"))))
|
14
|
1574 (setq w3-display-css-properties (css-get
|
16
|
1575 (nth 0 node)
|
|
1576 (nth 1 node)
|
14
|
1577 w3-current-stylesheet
|
|
1578 w3-display-open-element-stack))
|
|
1579 (if nofaces
|
|
1580 nil
|
|
1581 (push (w3-face-for-element node) w3-active-faces)
|
|
1582 (push (w3-voice-for-element node) w3-active-voices))
|
|
1583 (push (w3-get-style-info 'display node) break-style)
|
|
1584 (push (w3-get-style-info 'insert-after node) insert-after)
|
|
1585 (setq insert-before (w3-get-style-info 'insert-before node))
|
|
1586 (w3-display-handle-break)
|
|
1587 (if (w3-node-visible-p)
|
|
1588 nil
|
|
1589 (setq insert-before nil
|
|
1590 tag '*invisible)
|
|
1591 (setcar insert-after nil))
|
|
1592 (if insert-before
|
|
1593 (w3-handle-string-content insert-before))
|
|
1594 (setq insert-before nil)
|
|
1595 (if id
|
|
1596 (setq w3-id-positions (cons
|
|
1597 (cons (intern id)
|
|
1598 (set-marker (make-marker)
|
|
1599 (point-max)))
|
|
1600 w3-id-positions)))
|
|
1601 (case tag
|
|
1602 (a ; Hyperlinks
|
|
1603 (let* (
|
|
1604 (title (w3-get-attribute 'title))
|
|
1605 (name (or (w3-get-attribute 'id)
|
|
1606 (w3-get-attribute 'name)))
|
|
1607 (btdt nil)
|
|
1608 class
|
|
1609 (before nil)
|
|
1610 (after nil)
|
|
1611 (face nil)
|
|
1612 (voice nil)
|
|
1613 (st nil))
|
|
1614 (setq st (point)
|
|
1615 hyperlink-info (list
|
|
1616 st
|
|
1617 (append
|
|
1618 (list 'link :args nil
|
|
1619 :value "" :tag ""
|
|
1620 :action 'w3-follow-hyperlink
|
22
|
1621 :from (set-marker (make-marker) st)
|
14
|
1622 :help-echo 'w3-widget-echo
|
22
|
1623 :emacspeak-help 'w3-widget-echo
|
14
|
1624 )
|
|
1625 (alist-to-plist args))))
|
|
1626 (w3-handle-content node)
|
|
1627 )
|
|
1628 )
|
16
|
1629 ((ol ul dl menu)
|
|
1630 (push 0 w3-display-list-stack)
|
|
1631 (w3-handle-content node))
|
|
1632 (dir
|
14
|
1633 (push 0 w3-display-list-stack)
|
16
|
1634 (setq node
|
|
1635 (list tag args
|
|
1636 (list
|
|
1637 (list 'table nil
|
|
1638 (w3-display-chop-into-table node 3)))))
|
|
1639 (w3-handle-content node))
|
|
1640 (multicol
|
|
1641 (setq node (list tag args
|
|
1642 (list
|
|
1643 (list 'table nil
|
|
1644 (w3-display-chop-into-table node 2)))))
|
14
|
1645 (w3-handle-content node))
|
|
1646 (img ; inlined image
|
|
1647 (w3-handle-image)
|
|
1648 (w3-handle-empty-tag))
|
24
|
1649 (frameset
|
|
1650 (if w3-display-frames
|
|
1651 (w3-handle-content node)
|
|
1652 (w3-handle-empty-tag)))
|
|
1653 (frame
|
|
1654 (let* ((href (or (w3-get-attribute 'src)
|
|
1655 (w3-get-attribute 'href)))
|
|
1656 (name (or (w3-get-attribute 'name)
|
|
1657 (w3-get-attribute 'title)
|
|
1658 (w3-get-attribute 'alt)
|
|
1659 "Unknown frame name")))
|
|
1660 (w3-handle-content
|
|
1661 (list tag args
|
|
1662 (list
|
|
1663 (list 'p nil
|
|
1664 (list
|
|
1665 (list 'a
|
|
1666 (cons (cons 'href href)
|
|
1667 args)
|
|
1668 (list
|
|
1669 "Fetch frame: "
|
|
1670 name)))))))))
|
|
1671 (noframes
|
|
1672 (if w3-display-frames
|
|
1673 (w3-handle-empty-tag)
|
|
1674 (w3-handle-content node)))
|
14
|
1675 (script ; Scripts
|
|
1676 (w3-handle-empty-tag))
|
|
1677 ((embed object) ; Embedded images/content
|
|
1678 (w3-handle-content node)
|
|
1679 )
|
|
1680 (hr ; Cause line break & insert rule
|
|
1681 (let* ((perc (or (w3-get-attribute 'width)
|
|
1682 (w3-get-style-info 'width node)
|
|
1683 "100%"))
|
|
1684 (rule nil)
|
|
1685 (width nil))
|
|
1686 (setq perc (/ (min (string-to-int perc) 100) 100.0)
|
|
1687 width (* fill-column perc)
|
|
1688 rule (make-string (max (truncate width) 0)
|
|
1689 w3-horizontal-rule-char)
|
|
1690 node (list 'hr nil (list rule)))
|
|
1691 (w3-handle-content node)))
|
|
1692 (map ; Client side imagemaps
|
|
1693 (let ((name (or (w3-get-attribute 'name)
|
|
1694 (w3-get-attribute 'id)
|
|
1695 "unnamed"))
|
|
1696 (areas
|
|
1697 (mapcar
|
|
1698 (function
|
|
1699 (lambda (node)
|
|
1700 (let* ((args (nth 1 node))
|
|
1701 (type (downcase (or
|
|
1702 (w3-get-attribute 'shape)
|
|
1703 "rect")))
|
|
1704 (coords (w3-decode-area-coords
|
|
1705 (or (cdr-safe
|
|
1706 (assq 'coords args)) "")))
|
|
1707 (alt (w3-get-attribute 'alt))
|
|
1708 (href (if (assq 'nohref args)
|
|
1709 t
|
|
1710 (or (w3-get-attribute 'src)
|
|
1711 (w3-get-attribute 'href))))
|
|
1712 )
|
|
1713 (vector type coords href alt))
|
|
1714 )
|
|
1715 )
|
|
1716 (nth 2 node))))
|
|
1717 (setq w3-imagemaps (cons (cons name areas) w3-imagemaps)))
|
|
1718 (w3-handle-empty-tag)
|
|
1719 )
|
16
|
1720 (note
|
|
1721 ;; Ewwwwhhh. Looks gross, but it works. This converts a
|
|
1722 ;; <note> into a two-cell table, so that things look all
|
|
1723 ;; pretty.
|
|
1724 (setq node
|
|
1725 (list 'note nil
|
|
1726 (list
|
|
1727 (list 'table nil
|
|
1728 (list
|
|
1729 (list 'tr nil
|
|
1730 (list
|
|
1731 (list 'td (list 'align 'right)
|
|
1732 (list
|
|
1733 (concat
|
|
1734 (or (w3-get-attribute 'role)
|
|
1735 "CAUTION") ":")))
|
|
1736 (list 'td nil
|
|
1737 (nth 2 node)))))))))
|
|
1738 (w3-handle-content node)
|
|
1739 )
|
|
1740 (table
|
14
|
1741 (w3-display-table node)
|
|
1742 (setq w3-last-fill-pos (point))
|
|
1743 (w3-handle-empty-tag)
|
|
1744 )
|
|
1745 (isindex
|
|
1746 (let ((prompt (or (w3-get-attribute 'prompt)
|
|
1747 "Search on (+ separates keywords): "))
|
|
1748 action node)
|
|
1749 (setq action (or (w3-get-attribute 'src)
|
|
1750 (w3-get-attribute 'href)
|
|
1751 (url-view-url t)))
|
|
1752 (if (and prompt (string-match "[^: \t-]+$" prompt))
|
|
1753 (setq prompt (concat prompt ": ")))
|
|
1754 (setq node
|
|
1755 (list 'isindex nil
|
|
1756 (list
|
|
1757 (list 'hr nil nil)
|
|
1758 (list 'form
|
|
1759 (list (cons 'action action)
|
|
1760 (cons 'enctype
|
|
1761 "application/x-w3-isindex")
|
|
1762 (cons 'method "get"))
|
|
1763 (list
|
|
1764 prompt
|
|
1765 (list 'input
|
|
1766 (list (cons 'type "text")
|
|
1767 (cons 'name "isindex"))))))))
|
|
1768 (w3-handle-content node)
|
|
1769 (setq w3-current-isindex (cons action prompt)))
|
|
1770 )
|
|
1771 (*document
|
|
1772 (let ((info (mapcar (lambda (x) (cons x (symbol-value x)))
|
|
1773 w3-persistent-variables)))
|
16
|
1774 (if (not w3-display-same-buffer)
|
|
1775 (set-buffer (generate-new-buffer "Untitled")))
|
14
|
1776 (setq w3-current-form-number 0
|
|
1777 w3-display-open-element-stack nil
|
|
1778 w3-last-fill-pos (point-min)
|
|
1779 fill-column (min (- (or w3-strict-width (window-width))
|
|
1780 w3-right-margin)
|
|
1781 (or w3-maximum-line-length
|
|
1782 (window-width))))
|
|
1783 (switch-to-buffer (current-buffer))
|
|
1784 (buffer-disable-undo (current-buffer))
|
|
1785 (mapcar (function (lambda (x) (set (car x) (cdr x)))) info)
|
|
1786 ;; ACK! We don't like filladapt mode!
|
|
1787 (set (make-local-variable 'filladapt-mode) nil)
|
|
1788 (set (make-local-variable 'adaptive-fill-mode) nil)
|
16
|
1789 (set (make-local-variable 'voice-lock-mode) t)
|
14
|
1790 (setq w3-current-stylesheet (css-copy-stylesheet
|
|
1791 w3-user-stylesheet)
|
|
1792 w3-last-fill-pos (point)
|
|
1793 fill-column (min (- (or w3-strict-width (window-width))
|
|
1794 w3-right-margin)
|
|
1795 (or w3-maximum-line-length
|
|
1796 (window-width)))
|
|
1797 fill-prefix "")
|
24
|
1798 (set (make-local-variable 'inhibit-read-only) t))
|
14
|
1799 (w3-handle-content node)
|
|
1800 )
|
|
1801 (*invisible
|
|
1802 (w3-handle-empty-tag))
|
|
1803 (meta
|
|
1804 (let* ((equiv (cdr-safe (assq 'http-equiv args)))
|
|
1805 (value (w3-get-attribute 'content))
|
|
1806 (name (w3-get-attribute 'name))
|
|
1807 (node (and equiv (assoc (setq equiv (downcase equiv))
|
|
1808 url-current-mime-headers))))
|
|
1809 (if equiv
|
|
1810 (setq url-current-mime-headers (cons
|
|
1811 (cons equiv value)
|
|
1812 url-current-mime-headers)))
|
|
1813 (if name
|
|
1814 (setq w3-current-metainfo (cons
|
|
1815 (cons name value)
|
|
1816 w3-current-metainfo)))
|
|
1817
|
|
1818 ;; Special-case the Set-Cookie header
|
|
1819 (if (and equiv (string= (downcase equiv) "set-cookie"))
|
|
1820 (url-cookie-handle-set-cookie value))
|
|
1821 ;; Special-case the refresh header
|
|
1822 (if (and equiv (string= (downcase equiv) "refresh"))
|
|
1823 (url-handle-refresh-header value)))
|
|
1824 (w3-handle-empty-tag)
|
|
1825 )
|
|
1826 (link
|
|
1827 ;; This doesn't handle blank-separated values per the RFC.
|
|
1828 (w3-parse-link args)
|
|
1829 (w3-handle-empty-tag))
|
|
1830 (title
|
|
1831 (let ((potential-title "")
|
|
1832 (content (nth 2 node)))
|
|
1833 (while content
|
|
1834 (setq potential-title (concat potential-title (car content))
|
|
1835 content (cdr content)))
|
|
1836 (setq potential-title (w3-normalize-spaces potential-title))
|
16
|
1837 (if (or w3-display-same-buffer
|
|
1838 (string-match "^[ \t]*$" potential-title))
|
14
|
1839 nil
|
|
1840 (rename-buffer (generate-new-buffer-name
|
|
1841 (w3-fix-spaces potential-title)))))
|
|
1842 (w3-handle-empty-tag))
|
|
1843 (form
|
|
1844 (setq w3-current-form-number (1+ w3-current-form-number))
|
|
1845 (let* (
|
|
1846 (action (w3-get-attribute 'action))
|
|
1847 (url nil))
|
|
1848 (if (not action)
|
|
1849 (setq args (cons (cons 'action (url-view-url t)) args)))
|
16
|
1850 (setq w3-display-form-id (cons
|
|
1851 (cons 'form-number
|
|
1852 w3-current-form-number)
|
|
1853 args))
|
14
|
1854 (w3-handle-content node)))
|
20
|
1855 ; (keygen
|
|
1856 ; (w3-form-add-element 'keygen
|
|
1857 ; (or (w3-get-attribute 'name)
|
|
1858 ; (w3-get-attribute 'id)
|
|
1859 ; "keygen")
|
|
1860 ; nil ; value
|
|
1861 ; nil ; size
|
|
1862 ; nil ; maxlength
|
|
1863 ; nil ; default
|
|
1864 ; w3-display-form-id ; action
|
|
1865 ; nil ; options
|
|
1866 ; w3-current-form-number
|
|
1867 ; (w3-get-attribute 'id) ; id
|
|
1868 ; nil ; checked
|
|
1869 ; (car w3-active-faces)))
|
14
|
1870 (input
|
16
|
1871 (w3-form-add-element
|
|
1872 (w3-display-normalize-form-info args)
|
20
|
1873 w3-active-faces)
|
14
|
1874 (w3-handle-empty-tag)
|
|
1875 )
|
|
1876 (select
|
16
|
1877 (let* ((plist (w3-display-normalize-form-info args))
|
|
1878 (tmp nil)
|
|
1879 (multiple (assq 'multiple args))
|
|
1880 (value nil)
|
|
1881 (name (plist-get plist 'name))
|
|
1882 (options (mapcar
|
|
1883 (function
|
|
1884 (lambda (n)
|
|
1885 (setq tmp (w3-normalize-spaces
|
|
1886 (apply 'concat (nth 2 n)))
|
|
1887 tmp (cons tmp
|
|
1888 (or
|
|
1889 (cdr-safe
|
|
1890 (assq 'value (nth 1 n)))
|
|
1891 tmp)))
|
|
1892 (if (assq 'selected (nth 1 n))
|
|
1893 (setq value (car tmp)))
|
|
1894 tmp))
|
|
1895 (nth 2 node))))
|
|
1896 (if (not value)
|
|
1897 (setq value (caar options)))
|
|
1898 (setq plist (plist-put plist 'value value))
|
|
1899 (if multiple
|
|
1900 (progn
|
|
1901 (setq options
|
|
1902 (mapcar
|
|
1903 (function
|
|
1904 (lambda (opt)
|
|
1905 (list 'div nil
|
|
1906 (list
|
|
1907 (list 'input
|
|
1908 (list (cons 'name name)
|
|
1909 (cons 'type "checkbox")
|
|
1910 (cons 'value (car opt))))
|
|
1911 " " (car opt) (list 'br nil nil)))))
|
|
1912 options))
|
|
1913 (setq node (list 'p nil options))
|
|
1914 (w3-handle-content node))
|
|
1915 (setq plist (plist-put plist 'type 'option)
|
|
1916 plist (plist-put plist 'options options))
|
20
|
1917 (w3-form-add-element plist w3-active-faces)
|
14
|
1918 ;; This should really not be necessary, but some versions
|
|
1919 ;; of the widget library leave point _BEFORE_ the menu
|
|
1920 ;; widget instead of after.
|
|
1921 (goto-char (point-max))
|
16
|
1922 (w3-handle-empty-tag))))
|
14
|
1923 (textarea
|
16
|
1924 (let* ((plist (w3-display-normalize-form-info args))
|
|
1925 (value (w3-normalize-spaces
|
|
1926 (apply 'concat (nth 2 node)))))
|
|
1927 (setq plist (plist-put plist 'type 'multiline)
|
|
1928 plist (plist-put plist 'value value))
|
20
|
1929 (w3-form-add-element plist w3-active-faces))
|
14
|
1930 (w3-handle-empty-tag)
|
|
1931 )
|
|
1932 (style
|
16
|
1933 (w3-handle-style (alist-to-plist
|
|
1934 (cons (cons 'data (apply 'concat (nth 2 node)))
|
|
1935 (nth 1 node))))
|
14
|
1936 (w3-handle-empty-tag))
|
16
|
1937 ;; Emacs-W3 stuff that cannot be expressed in a stylesheet
|
|
1938 (pinhead
|
|
1939 ;; This check is so that we don't screw up table auto-layout
|
|
1940 ;; by changing our text midway through the parse/layout/display
|
|
1941 ;; steps.
|
|
1942 (if (nth 2 node)
|
|
1943 nil
|
|
1944 (setcar (cddr node)
|
|
1945 (list
|
|
1946 (if (fboundp 'yow)
|
|
1947 (yow)
|
|
1948 "AIEEEEE! I am having an UNDULATING EXPERIENCE!"))))
|
|
1949 (w3-handle-content node))
|
|
1950 (flame
|
|
1951 (if (nth 2 node)
|
|
1952 nil
|
|
1953 (setcar
|
|
1954 (cddr node)
|
|
1955 (list
|
|
1956 (condition-case ()
|
|
1957 (concat
|
|
1958 (sentence-ify
|
|
1959 (string-ify
|
|
1960 (append-suffixes-hack (flatten (*flame))))))
|
|
1961 (error
|
|
1962 "You know, everything is really a graphics editor.")))))
|
|
1963 (w3-handle-content node))
|
|
1964 (cookie
|
|
1965 (if (nth 2 node)
|
|
1966 nil
|
|
1967 (setcar
|
|
1968 (cddr node)
|
|
1969 (list
|
|
1970 (w3-display-get-cookie args))))
|
|
1971 (w3-handle-content node))
|
|
1972 ;; Generic formatting - all things that can be fully specified
|
|
1973 ;; by a CSS stylesheet.
|
14
|
1974 (otherwise
|
|
1975 (w3-handle-content node))
|
|
1976 ) ; case tag
|
|
1977 ) ; stringp content
|
|
1978 ) ; while content
|
|
1979 ) ; while content-stack
|
|
1980 )
|
|
1981 )
|
|
1982
|
|
1983 (defun w3-draw-tree (tree)
|
|
1984 ;; The main entry point - wow complicated
|
|
1985 (setq w3-current-stylesheet w3-user-stylesheet)
|
|
1986 (while tree
|
|
1987 (w3-display-node (car tree))
|
|
1988 (setq tree (cdr tree)))
|
|
1989 (w3-display-fix-widgets)
|
|
1990 (w3-form-resurrect-widgets))
|
|
1991
|
|
1992 (defun time-display (&optional tree)
|
|
1993 ;; Return the # of seconds it took to draw 'tree'
|
|
1994 (let ((st (nth 1 (current-time)))
|
|
1995 (nd nil))
|
|
1996 (w3-draw-tree (or tree w3-last-parse-tree))
|
|
1997 (setq nd (nth 1 (current-time)))
|
|
1998 (- nd st)))
|
|
1999
|
|
2000
|
20
|
2001 (defun w3-fixup-eol-faces ()
|
|
2002 ;; Remove 'face property at end of lines - underlining screws up stuff
|
|
2003 (let ((inhibit-read-only t))
|
|
2004 (save-excursion
|
|
2005 (goto-char (point-min))
|
|
2006 (while (search-forward "\n" nil t)
|
|
2007 (put-text-property (match-beginning 0) (match-end 0) 'face nil)))))
|
|
2008
|
16
|
2009 (defsubst w3-finish-drawing ()
|
20
|
2010 (let (url glyph widget)
|
|
2011 (while w3-image-widgets-waiting
|
|
2012 (setq widget (car w3-image-widgets-waiting)
|
|
2013 w3-image-widgets-waiting (cdr w3-image-widgets-waiting)
|
|
2014 url (widget-get widget 'src)
|
|
2015 glyph (cdr-safe (assoc url w3-graphics-list)))
|
|
2016 (condition-case nil
|
|
2017 (widget-value-set widget glyph)
|
|
2018 (error nil))))
|
|
2019 (and (not w3-running-xemacs)
|
|
2020 (not (eq (device-type) 'tty))
|
|
2021 (w3-fixup-eol-faces))
|
|
2022 ;;(w3-handle-headers)
|
16
|
2023 )
|
|
2024
|
|
2025 (defun w3-region (st nd)
|
|
2026 (if (not w3-setup-done) (w3-do-setup))
|
|
2027 (let* ((source (buffer-substring st nd))
|
20
|
2028 (w3-dislplay-same-buffer t)
|
16
|
2029 (parse nil))
|
20
|
2030 (save-window-excursion
|
|
2031 (save-excursion
|
|
2032 (set-buffer (get-buffer-create " *w3-region*"))
|
|
2033 (erase-buffer)
|
|
2034 (insert source)
|
|
2035 (setq parse (w3-parse-buffer (current-buffer))))
|
|
2036 (narrow-to-region st nd)
|
|
2037 (delete-region (point-min) (point-max))
|
|
2038 (w3-draw-tree parse)
|
|
2039 (w3-finish-drawing)
|
|
2040 (widen))))
|
16
|
2041
|
|
2042 (defun w3-refresh-buffer ()
|
|
2043 (interactive)
|
|
2044 (let ((parse w3-current-parse)
|
|
2045 (inhibit-read-only t)
|
|
2046 (w3-display-same-buffer t))
|
|
2047 (if (not parse)
|
|
2048 (error "Could not find the parse tree for this buffer. EEEEK!"))
|
|
2049 (erase-buffer)
|
|
2050 (w3-draw-tree parse)
|
|
2051 (w3-finish-drawing)
|
|
2052 (w3-mode)
|
|
2053 (set-buffer-modified-p nil)))
|
|
2054
|
14
|
2055 (defun w3-prepare-buffer (&rest args)
|
|
2056 ;; The text/html viewer - does all the drawing and displaying of the buffer
|
|
2057 ;; that is necessary to go from raw HTML to a good presentation.
|
|
2058 (let* ((source (buffer-string))
|
|
2059 (source-buf (current-buffer))
|
|
2060 (parse (w3-parse-buffer source-buf)))
|
|
2061 (set-buffer-modified-p nil)
|
|
2062 (w3-draw-tree parse)
|
|
2063 (kill-buffer source-buf)
|
|
2064 (set-buffer-modified-p nil)
|
|
2065 (setq w3-current-source source
|
|
2066 w3-current-parse parse)
|
16
|
2067 (w3-finish-drawing)
|
14
|
2068 (w3-mode)
|
|
2069 (set-buffer-modified-p nil)
|
|
2070 (goto-char (point-min))
|
|
2071 (if url-keep-history
|
|
2072 (let ((url (url-view-url t)))
|
|
2073 (if (not url-history-list)
|
|
2074 (setq url-history-list (make-hash-table :size 131 :test 'equal)))
|
|
2075 (cl-puthash url (buffer-name) url-history-list)
|
|
2076 (if (fboundp 'w3-shuffle-history-menu)
|
|
2077 (w3-shuffle-history-menu)))))
|
|
2078 )
|
|
2079
|
|
2080 (provide 'w3-display)
|