* shr.el: Rework the way things are indented by <li> slightly.
[gnus] / lisp / shr.el
1 ;;; shr.el --- Simple HTML Renderer
2
3 ;; Copyright (C) 2010 Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: html
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
22
23 ;;; Commentary:
24
25 ;; This package takes a HTML parse tree (as provided by
26 ;; libxml-parse-html-region) and renders it in the current buffer.  It
27 ;; does not do CSS, JavaScript or anything advanced: It's geared
28 ;; towards rendering typical short snippets of HTML, like what you'd
29 ;; find in HTML email and the like.
30
31 ;;; Code:
32
33 (eval-when-compile (require 'cl))
34 (require 'browse-url)
35
36 (defgroup shr nil
37   "Simple HTML Renderer"
38   :group 'mail)
39
40 (defcustom shr-max-image-proportion 0.9
41   "How big pictures displayed are in relation to the window they're in.
42 A value of 0.7 means that they are allowed to take up 70% of the
43 width and height of the window.  If they are larger than this,
44 and Emacs supports it, then the images will be rescaled down to
45 fit these criteria."
46   :version "24.1"
47   :group 'shr
48   :type 'float)
49
50 (defcustom shr-blocked-images nil
51   "Images that have URLs matching this regexp will be blocked."
52   :version "24.1"
53   :group 'shr
54   :type 'regexp)
55
56 (defcustom shr-table-line ?-
57   "Character used to draw table line."
58   :group 'shr
59   :type 'char)
60
61 (defcustom shr-table-corner ?+
62   "Charater used to draw table corner."
63   :group 'shr
64   :type 'char)
65
66 (defvar shr-content-function nil
67   "If bound, this should be a function that will return the content.
68 This is used for cid: URLs, and the function is called with the
69 cid: URL as the argument.")
70
71 (defvar shr-width 70
72   "Frame width to use for rendering.")
73
74 ;;; Internal variables.
75
76 (defvar shr-folding-mode nil)
77 (defvar shr-state nil)
78 (defvar shr-start nil)
79 (defvar shr-indentation 0)
80 (defvar shr-inhibit-images nil)
81 (defvar shr-list-mode nil)
82 (defvar shr-content-cache nil)
83
84 (defvar shr-map
85   (let ((map (make-sparse-keymap)))
86     (define-key map "a" 'shr-show-alt-text)
87     (define-key map "i" 'shr-browse-image)
88     (define-key map "I" 'shr-insert-image)
89     (define-key map "u" 'shr-copy-url)
90     (define-key map "v" 'shr-browse-url)
91     (define-key map "\r" 'shr-browse-url)
92     map))
93
94 ;; Public functions and commands.
95
96 ;;;###autoload
97 (defun shr-insert-document (dom)
98   (setq shr-content-cache nil)
99   (let ((shr-state nil)
100         (shr-start nil))
101     (shr-descend (shr-transform-dom dom))))
102
103 (defun shr-copy-url ()
104   "Copy the URL under point to the kill ring.
105 If called twice, then try to fetch the URL and see whether it
106 redirects somewhere else."
107   (interactive)
108   (let ((url (get-text-property (point) 'shr-url)))
109     (cond
110      ((not url)
111       (message "No URL under point"))
112      ;; Resolve redirected URLs.
113      ((equal url (car kill-ring))
114       (url-retrieve
115        url
116        (lambda (a)
117          (when (and (consp a)
118                     (eq (car a) :redirect))
119            (with-temp-buffer
120              (insert (cadr a))
121              (goto-char (point-min))
122              ;; Remove common tracking junk from the URL.
123              (when (re-search-forward ".utm_.*" nil t)
124                (replace-match "" t t))
125              (message "Copied %s" (buffer-string))
126              (copy-region-as-kill (point-min) (point-max)))))))
127      ;; Copy the URL to the kill ring.
128      (t
129       (with-temp-buffer
130         (insert url)
131         (copy-region-as-kill (point-min) (point-max))
132         (message "Copied %s" url))))))
133
134 (defun shr-show-alt-text ()
135   "Show the ALT text of the image under point."
136   (interactive)
137   (let ((text (get-text-property (point) 'shr-alt)))
138     (if (not text)
139         (message "No image under point")
140       (message "%s" text))))
141
142 (defun shr-browse-image ()
143   "Browse the image under point."
144   (interactive)
145   (let ((url (get-text-property (point) 'shr-image)))
146     (if (not url)
147         (message "No image under point")
148       (message "Browsing %s..." url)
149       (browse-url url))))
150
151 (defun shr-insert-image ()
152   "Insert the image under point into the buffer."
153   (interactive)
154   (let ((url (get-text-property (point) 'shr-image)))
155     (if (not url)
156         (message "No image under point")
157       (message "Inserting %s..." url)
158       (url-retrieve url 'shr-image-fetched
159                     (list (current-buffer) (1- (point)) (point-marker))
160                     t))))
161
162 ;;; Utility functions.
163
164 (defun shr-transform-dom (dom)
165   (let ((result (list (pop dom))))
166     (dolist (arg (pop dom))
167       (push (cons (intern (concat ":" (symbol-name (car arg))) obarray)
168                   (cdr arg))
169             result))
170     (dolist (sub dom)
171       (if (stringp sub)
172           (push (cons :text sub) result)
173         (push (shr-transform-dom sub) result)))
174     (nreverse result)))
175
176 (defun shr-descend (dom)
177   (let ((function (intern (concat "shr-tag-" (symbol-name (car dom))) obarray)))
178     (if (fboundp function)
179         (funcall function (cdr dom))
180       (shr-generic (cdr dom)))))
181
182 (defun shr-generic (cont)
183   (dolist (sub cont)
184     (cond
185      ((eq (car sub) :text)
186       (shr-insert (cdr sub)))
187      ((listp (cdr sub))
188       (shr-descend sub)))))
189
190 (defun shr-insert (text)
191   (when (eq shr-state 'image)
192     (insert "\n")
193     (setq shr-state nil))
194   (cond
195    ((eq shr-folding-mode 'none)
196     (insert text))
197    (t
198     (let ((first t)
199           column)
200       (when (and (string-match "\\`[ \t\n]" text)
201                  (not (bolp))
202                  (not (eq (char-after (1- (point))) ? )))
203         (insert " "))
204       (dolist (elem (split-string text))
205         (when (and (bolp)
206                    (> shr-indentation 0))
207           (shr-indent))
208         ;; The shr-start is a special variable that is used to pass
209         ;; upwards the first point in the buffer where the text really
210         ;; starts.
211         (unless shr-start
212           (setq shr-start (point)))
213         (insert elem)
214         (when (> (current-column) shr-width)
215           (if (not (search-backward " " (line-beginning-position) t))
216               (insert "\n")
217             (delete-char 1)
218             (insert "\n")
219             (put-text-property (1- (point)) (point) 'shr-break t)
220             (when (> shr-indentation 0)
221               (shr-indent))
222             (end-of-line)))
223         (insert " "))
224       (unless (string-match "[ \t\n]\\'" text)
225         (delete-char -1))))))
226
227 (defun shr-ensure-newline ()
228   (unless (zerop (current-column))
229     (insert "\n")))
230
231 (defun shr-ensure-paragraph ()
232   (unless (bobp)
233     (if (<= (current-column) shr-indentation)
234         (unless (save-excursion
235                   (forward-line -1)
236                   (looking-at " *$"))
237           (insert "\n"))
238       (if (save-excursion
239             (beginning-of-line)
240             (looking-at " *$"))
241           (insert "\n")
242         (insert "\n\n")))))
243
244 (defun shr-indent ()
245   (when (> shr-indentation 0)
246     (insert (make-string shr-indentation ? ))))
247
248 (defun shr-fontize-cont (cont &rest types)
249   (let (shr-start)
250     (shr-generic cont)
251     (dolist (type types)
252       (shr-add-font (or shr-start (point)) (point) type))))
253
254 (defun shr-add-font (start end type)
255   (let ((overlay (make-overlay start end)))
256     (overlay-put overlay 'face type)))
257
258 (defun shr-browse-url ()
259   "Browse the URL under point."
260   (interactive)
261   (let ((url (get-text-property (point) 'shr-url)))
262     (if (not url)
263         (message "No link under point")
264       (browse-url url))))
265
266 (defun shr-image-fetched (status buffer start end)
267   (when (and (buffer-name buffer)
268              (not (plist-get status :error)))
269     (url-store-in-cache (current-buffer))
270     (when (or (search-forward "\n\n" nil t)
271               (search-forward "\r\n\r\n" nil t))
272       (let ((data (buffer-substring (point) (point-max))))
273         (with-current-buffer buffer
274           (let ((alt (buffer-substring start end))
275                 (inhibit-read-only t))
276             (delete-region start end)
277             (shr-put-image data start alt))))))
278   (kill-buffer (current-buffer)))
279
280 (defun shr-put-image (data point alt)
281   (if (not (display-graphic-p))
282       (insert alt)
283     (let ((image (ignore-errors
284                    (shr-rescale-image data))))
285       (when image
286         (put-image image point alt)))))
287
288 (defun shr-rescale-image (data)
289   (if (or (not (fboundp 'imagemagick-types))
290           (not (get-buffer-window (current-buffer))))
291       (create-image data nil t)
292     (let* ((image (create-image data nil t))
293            (size (image-size image t))
294            (width (car size))
295            (height (cdr size))
296            (edges (window-inside-pixel-edges
297                    (get-buffer-window (current-buffer))))
298            (window-width (truncate (* shr-max-image-proportion
299                                       (- (nth 2 edges) (nth 0 edges)))))
300            (window-height (truncate (* shr-max-image-proportion
301                                        (- (nth 3 edges) (nth 1 edges)))))
302            scaled-image)
303       (when (> height window-height)
304         (setq image (or (create-image data 'imagemagick t
305                                       :height window-height)
306                         image))
307         (setq size (image-size image t)))
308       (when (> (car size) window-width)
309         (setq image (or
310                      (create-image data 'imagemagick t
311                                    :width window-width)
312                      image)))
313       image)))
314
315 (defun shr-get-image-data (url)
316   "Get image data for URL.
317 Return a string with image data."
318   (with-temp-buffer
319     (mm-disable-multibyte)
320     (when (ignore-errors
321             (url-cache-extract (url-cache-create-filename url))
322             t)
323       (when (or (search-forward "\n\n" nil t)
324                 (search-forward "\r\n\r\n" nil t))
325         (buffer-substring (point) (point-max))))))
326
327 (defun shr-heading (cont &rest types)
328   (shr-ensure-paragraph)
329   (apply #'shr-fontize-cont cont types)
330   (shr-ensure-paragraph))
331
332 ;;; Tag-specific rendering rules.
333
334 (defun shr-tag-p (cont)
335   (shr-ensure-paragraph)
336   (shr-indent)
337   (shr-generic cont)
338   (shr-ensure-paragraph))
339
340 (defun shr-tag-b (cont)
341   (shr-fontize-cont cont 'bold))
342
343 (defun shr-tag-i (cont)
344   (shr-fontize-cont cont 'italic))
345
346 (defun shr-tag-em (cont)
347   (shr-fontize-cont cont 'bold))
348
349 (defun shr-tag-u (cont)
350   (shr-fontize-cont cont 'underline))
351
352 (defun shr-tag-s (cont)
353   (shr-fontize-cont cont 'strike-through))
354
355 (defun shr-tag-a (cont)
356   (let ((url (cdr (assq :href cont)))
357         (start (point))
358         shr-start)
359     (shr-generic cont)
360     (widget-convert-button
361      'link (or shr-start start) (point)
362      :help-echo url)
363     (put-text-property (or shr-start start) (point) 'keymap shr-map)
364     (put-text-property (or shr-start start) (point) 'shr-url url)))
365
366 (defun shr-tag-img (cont)
367   (when (and (> (current-column) 0)
368              (not (eq shr-state 'image)))
369     (insert "\n"))
370   (let ((start (point-marker)))
371     (let ((alt (cdr (assq :alt cont)))
372           (url (cdr (assq :src cont))))
373       (when (zerop (length alt))
374         (setq alt "[img]"))
375       (cond
376        ((and (not shr-inhibit-images)
377              (string-match "\\`cid:" url))
378         (let ((url (substring url (match-end 0)))
379               image)
380           (if (or (not shr-content-function)
381                   (not (setq image (funcall shr-content-function url))))
382               (insert alt)
383             (shr-put-image image (point) alt))))
384        ((or shr-inhibit-images
385             (and shr-blocked-images
386                  (string-match shr-blocked-images url)))
387         (setq shr-start (point))
388         (let ((shr-state 'space))
389           (if (> (length alt) 8)
390               (shr-insert (substring alt 0 8))
391             (shr-insert alt))))
392        ((url-is-cached (browse-url-url-encode-chars url "[&)$ ]"))
393         (shr-put-image (shr-get-image-data url) (point) alt))
394        (t
395         (insert alt)
396         (ignore-errors
397           (url-retrieve url 'shr-image-fetched
398                         (list (current-buffer) start (point-marker))
399                         t))))
400       (insert " ")
401       (put-text-property start (point) 'keymap shr-map)
402       (put-text-property start (point) 'shr-alt alt)
403       (put-text-property start (point) 'shr-image url)
404       (setq shr-state 'image))))
405
406 (defun shr-tag-pre (cont)
407   (let ((shr-folding-mode 'none))
408     (shr-ensure-newline)
409     (shr-indent)
410     (shr-generic cont)
411     (shr-ensure-newline)))
412
413 (defun shr-tag-blockquote (cont)
414   (shr-ensure-paragraph)
415   (shr-indent)
416   (let ((shr-indentation (+ shr-indentation 4)))
417     (shr-generic cont))
418   (shr-ensure-paragraph))
419
420 (defun shr-tag-ul (cont)
421   (shr-ensure-paragraph)
422   (let ((shr-list-mode 'ul))
423     (shr-generic cont))
424   (shr-ensure-paragraph))
425
426 (defun shr-tag-ol (cont)
427   (shr-ensure-paragraph)
428   (let ((shr-list-mode 1))
429     (shr-generic cont))
430   (shr-ensure-paragraph))
431
432 (defun shr-tag-li (cont)
433   (shr-ensure-paragraph)
434   (shr-indent)
435   (let* ((bullet
436           (if (numberp shr-list-mode)
437               (prog1
438                   (format "%d " shr-list-mode)
439                 (setq shr-list-mode (1+ shr-list-mode)))
440             "* "))
441          (shr-indentation (+ shr-indentation (length bullet))))
442     (insert bullet)
443     (shr-generic cont)))
444
445 (defun shr-tag-br (cont)
446   (unless (bobp)
447     (insert "\n")
448     (shr-indent))
449   (shr-generic cont))
450
451 (defun shr-tag-h1 (cont)
452   (shr-heading cont 'bold 'underline))
453
454 (defun shr-tag-h2 (cont)
455   (shr-heading cont 'bold))
456
457 (defun shr-tag-h3 (cont)
458   (shr-heading cont 'italic))
459
460 (defun shr-tag-h4 (cont)
461   (shr-heading cont))
462
463 (defun shr-tag-h5 (cont)
464   (shr-heading cont))
465
466 (defun shr-tag-h6 (cont)
467   (shr-heading cont))
468
469 (defun shr-tag-hr (cont)
470   (shr-ensure-newline)
471   (insert (make-string shr-width ?-) "\n"))
472
473 ;;; Table rendering algorithm.
474
475 ;; Table rendering is the only complicated thing here.  We do this by
476 ;; first counting how many TDs there are in each TR, and registering
477 ;; how wide they think they should be ("width=45%", etc).  Then we
478 ;; render each TD separately (this is done in temporary buffers, so
479 ;; that we can use all the rendering machinery as if we were in the
480 ;; main buffer).  Now we know how much space each TD really takes, so
481 ;; we then render everything again with the new widths, and finally
482 ;; insert all these boxes into the main buffer.
483 (defun shr-tag-table (cont)
484   (shr-ensure-paragraph)
485   (setq cont (or (cdr (assq 'tbody cont))
486                  cont))
487   (let* ((shr-inhibit-images t)
488          ;; Find all suggested widths.
489          (columns (shr-column-specs cont))
490          ;; Compute how many characters wide each TD should be.
491          (suggested-widths (shr-pro-rate-columns columns))
492          ;; Do a "test rendering" to see how big each TD is (this can
493          ;; be smaller (if there's little text) or bigger (if there's
494          ;; unbreakable text).
495          (sketch (shr-make-table cont suggested-widths))
496          (sketch-widths (shr-table-widths sketch suggested-widths)))
497     ;; Then render the table again with these new "hard" widths.
498     (shr-insert-table (shr-make-table cont sketch-widths t) sketch-widths))
499   ;; Finally, insert all the images after the table.  The Emacs buffer
500   ;; model isn't strong enough to allow us to put the images actually
501   ;; into the tables.
502   (dolist (elem (shr-find-elements cont 'img))
503     (shr-tag-img (cdr elem))))
504
505 (defun shr-find-elements (cont type)
506   (let (result)
507     (dolist (elem cont)
508       (cond ((eq (car elem) type)
509              (push elem result))
510             ((consp (cdr elem))
511              (setq result (nconc (shr-find-elements (cdr elem) type) result)))))
512     (nreverse result)))
513
514 (defun shr-insert-table (table widths)
515   (shr-insert-table-ruler widths)
516   (dolist (row table)
517     (let ((start (point))
518           (height (let ((max 0))
519                     (dolist (column row)
520                       (setq max (max max (cadr column))))
521                     max)))
522       (dotimes (i height)
523         (shr-indent)
524         (insert "|\n"))
525       (dolist (column row)
526         (goto-char start)
527         (let ((lines (nth 2 column))
528               (overlay-lines (nth 3 column))
529               overlay overlay-line)
530           (dolist (line lines)
531             (setq overlay-line (pop overlay-lines))
532             (end-of-line)
533             (insert line "|")
534             (dolist (overlay overlay-line)
535               (let ((o (make-overlay (- (point) (nth 0 overlay) 1)
536                                      (- (point) (nth 1 overlay) 1)))
537                     (properties (nth 2 overlay)))
538                 (while properties
539                   (overlay-put o (pop properties) (pop properties)))))
540             (forward-line 1))
541           ;; Add blank lines at padding at the bottom of the TD,
542           ;; possibly.
543           (dotimes (i (- height (length lines)))
544             (end-of-line)
545             (insert (make-string (length (car lines)) ? ) "|")
546             (forward-line 1)))))
547     (shr-insert-table-ruler widths)))
548
549 (defun shr-insert-table-ruler (widths)
550   (shr-indent)
551   (insert shr-table-corner)
552   (dotimes (i (length widths))
553     (insert (make-string (aref widths i) shr-table-line) shr-table-corner))
554   (insert "\n"))
555
556 (defun shr-table-widths (table suggested-widths)
557   (let* ((length (length suggested-widths))
558          (widths (make-vector length 0))
559          (natural-widths (make-vector length 0)))
560     (dolist (row table)
561       (let ((i 0))
562         (dolist (column row)
563           (aset widths i (max (aref widths i)
564                               (car column)))
565           (aset natural-widths i (max (aref natural-widths i)
566                                       (cadr column)))
567           (setq i (1+ i)))))
568     (let ((extra (- (apply '+ (append suggested-widths nil))
569                     (apply '+ (append widths nil))))
570           (expanded-columns 0))
571       (when (> extra 0)
572         (dotimes (i length)
573           ;; If the natural width is wider than the rendered width, we
574           ;; want to allow the column to expand.
575           (when (> (aref natural-widths i) (aref widths i))
576             (setq expanded-columns (1+ expanded-columns))))
577         (dotimes (i length)
578           (when (> (aref natural-widths i) (aref widths i))
579             (aset widths i (min
580                             (1+ (aref natural-widths i))
581                             (+ (/ extra expanded-columns)
582                                (aref widths i))))))))
583     widths))
584
585 (defun shr-make-table (cont widths &optional fill)
586   (let ((trs nil))
587     (dolist (row cont)
588       (when (eq (car row) 'tr)
589         (let ((tds nil)
590               (columns (cdr row))
591               (i 0)
592               column)
593           (while (< i (length widths))
594             (setq column (pop columns))
595             (when (or (memq (car column) '(td th))
596                       (null column))
597               (push (shr-render-td (cdr column) (aref widths i) fill)
598                     tds)
599               (setq i (1+ i))))
600           (push (nreverse tds) trs))))
601     (nreverse trs)))
602
603 (defun shr-render-td (cont width fill)
604   (with-temp-buffer
605     (let ((cache (cdr (assoc (cons width cont) shr-content-cache))))
606       (if cache
607           (insert cache)
608         (let ((shr-width width)
609               (shr-indentation 0))
610           (shr-generic cont))
611         (delete-region
612          (point)
613          (+ (point)
614             (skip-chars-backward " \t\n")))
615         (push (cons (cons width cont) (buffer-string))
616               shr-content-cache)))
617     (goto-char (point-min))
618     (let ((max 0))
619       (while (not (eobp))
620         (end-of-line)
621         (setq max (max max (current-column)))
622         (forward-line 1))
623       (when fill
624         (goto-char (point-min))
625         ;; If the buffer is totally empty, then put a single blank
626         ;; line here.
627         (if (zerop (buffer-size))
628             (insert (make-string width ? ))
629           ;; Otherwise, fill the buffer.
630           (while (not (eobp))
631             (end-of-line)
632             (when (> (- width (current-column)) 0)
633               (insert (make-string (- width (current-column)) ? )))
634             (forward-line 1))))
635       (if fill
636           (list max
637                 (count-lines (point-min) (point-max))
638                 (split-string (buffer-string) "\n")
639                 (shr-collect-overlays))
640         (list max
641               (shr-natural-width))))))
642
643 (defun shr-natural-width ()
644   (goto-char (point-min))
645   (let ((current 0)
646         (max 0))
647     (while (not (eobp))
648       (end-of-line)
649       (setq current (+ current (current-column)))
650       (unless (get-text-property (point) 'shr-break)
651         (setq max (max max current)
652               current 0))
653       (forward-line 1))
654     max))
655
656 (defun shr-collect-overlays ()
657   (save-excursion
658     (goto-char (point-min))
659     (let ((overlays nil))
660       (while (not (eobp))
661         (push (shr-overlays-in-region (point) (line-end-position))
662               overlays)
663         (forward-line 1))
664       (nreverse overlays))))
665
666 (defun shr-overlays-in-region (start end)
667   (let (result)
668     (dolist (overlay (overlays-in start end))
669       (push (list (if (> start (overlay-start overlay))
670                       (- end start)
671                     (- end (overlay-start overlay)))
672                   (if (< end (overlay-end overlay))
673                       0
674                     (- end (overlay-end overlay)))
675                   (overlay-properties overlay))
676             result))
677     (nreverse result)))
678
679 (defun shr-pro-rate-columns (columns)
680   (let ((total-percentage 0)
681         (widths (make-vector (length columns) 0)))
682     (dotimes (i (length columns))
683       (setq total-percentage (+ total-percentage (aref columns i))))
684     (setq total-percentage (/ 1.0 total-percentage))
685     (dotimes (i (length columns))
686       (aset widths i (max (truncate (* (aref columns i)
687                                        total-percentage
688                                        (- shr-width (1+ (length columns)))))
689                           10)))
690     widths))
691
692 ;; Return a summary of the number and shape of the TDs in the table.
693 (defun shr-column-specs (cont)
694   (let ((columns (make-vector (shr-max-columns cont) 1)))
695     (dolist (row cont)
696       (when (eq (car row) 'tr)
697         (let ((i 0))
698           (dolist (column (cdr row))
699             (when (memq (car column) '(td th))
700               (let ((width (cdr (assq :width (cdr column)))))
701                 (when (and width
702                            (string-match "\\([0-9]+\\)%" width))
703                   (aset columns i
704                         (/ (string-to-number (match-string 1 width))
705                            100.0))))
706               (setq i (1+ i)))))))
707     columns))
708
709 (defun shr-count (cont elem)
710   (let ((i 0))
711     (dolist (sub cont)
712       (when (eq (car sub) elem)
713         (setq i (1+ i))))
714     i))
715
716 (defun shr-max-columns (cont)
717   (let ((max 0))
718     (dolist (row cont)
719       (when (eq (car row) 'tr)
720         (setq max (max max (+ (shr-count (cdr row) 'td)
721                               (shr-count (cdr row) 'th))))))
722     max))
723
724 (provide 'shr)
725
726 ;;; shr.el ends here