Allow shr table char to be customized
[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 (bolp)
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   (insert (make-string shr-indentation ? )))
246
247 (defun shr-fontize-cont (cont &rest types)
248   (let (shr-start)
249     (shr-generic cont)
250     (dolist (type types)
251       (shr-add-font (or shr-start (point)) (point) type))))
252
253 (defun shr-add-font (start end type)
254   (let ((overlay (make-overlay start end)))
255     (overlay-put overlay 'face type)))
256
257 (defun shr-browse-url ()
258   "Browse the URL under point."
259   (interactive)
260   (let ((url (get-text-property (point) 'shr-url)))
261     (if (not url)
262         (message "No link under point")
263       (browse-url url))))
264
265 (defun shr-image-fetched (status buffer start end)
266   (when (and (buffer-name buffer)
267              (not (plist-get status :error)))
268     (url-store-in-cache (current-buffer))
269     (when (or (search-forward "\n\n" nil t)
270               (search-forward "\r\n\r\n" nil t))
271       (let ((data (buffer-substring (point) (point-max))))
272         (with-current-buffer buffer
273           (let ((alt (buffer-substring start end))
274                 (inhibit-read-only t))
275             (delete-region start end)
276             (shr-put-image data start alt))))))
277   (kill-buffer (current-buffer)))
278
279 (defun shr-put-image (data point alt)
280   (if (not (display-graphic-p))
281       (insert alt)
282     (let ((image (ignore-errors
283                    (shr-rescale-image data))))
284       (when image
285         (put-image image point alt)))))
286
287 (defun shr-rescale-image (data)
288   (if (or (not (fboundp 'imagemagick-types))
289           (not (get-buffer-window (current-buffer))))
290       (create-image data nil t)
291     (let* ((image (create-image data nil t))
292            (size (image-size image t))
293            (width (car size))
294            (height (cdr size))
295            (edges (window-inside-pixel-edges
296                    (get-buffer-window (current-buffer))))
297            (window-width (truncate (* shr-max-image-proportion
298                                       (- (nth 2 edges) (nth 0 edges)))))
299            (window-height (truncate (* shr-max-image-proportion
300                                        (- (nth 3 edges) (nth 1 edges)))))
301            scaled-image)
302       (when (> height window-height)
303         (setq image (or (create-image data 'imagemagick t
304                                       :height window-height)
305                         image))
306         (setq size (image-size image t)))
307       (when (> (car size) window-width)
308         (setq image (or
309                      (create-image data 'imagemagick t
310                                    :width window-width)
311                      image)))
312       image)))
313
314 (defun shr-get-image-data (url)
315   "Get image data for URL.
316 Return a string with image data."
317   (with-temp-buffer
318     (mm-disable-multibyte)
319     (when (ignore-errors
320             (url-cache-extract (url-cache-create-filename url))
321             t)
322       (when (or (search-forward "\n\n" nil t)
323                 (search-forward "\r\n\r\n" nil t))
324         (buffer-substring (point) (point-max))))))
325
326 (defun shr-heading (cont &rest types)
327   (shr-ensure-paragraph)
328   (apply #'shr-fontize-cont cont types)
329   (shr-ensure-paragraph))
330
331 ;;; Tag-specific rendering rules.
332
333 (defun shr-tag-p (cont)
334   (shr-ensure-paragraph)
335   (shr-generic cont)
336   (shr-ensure-paragraph))
337
338 (defun shr-tag-b (cont)
339   (shr-fontize-cont cont 'bold))
340
341 (defun shr-tag-i (cont)
342   (shr-fontize-cont cont 'italic))
343
344 (defun shr-tag-em (cont)
345   (shr-fontize-cont cont 'bold))
346
347 (defun shr-tag-u (cont)
348   (shr-fontize-cont cont 'underline))
349
350 (defun shr-tag-s (cont)
351   (shr-fontize-cont cont 'strike-through))
352
353 (defun shr-tag-a (cont)
354   (let ((url (cdr (assq :href cont)))
355         (start (point))
356         shr-start)
357     (shr-generic cont)
358     (widget-convert-button
359      'link (or shr-start start) (point)
360      :help-echo url)
361     (put-text-property (or shr-start start) (point) 'keymap shr-map)
362     (put-text-property (or shr-start start) (point) 'shr-url url)))
363
364 (defun shr-tag-img (cont)
365   (when (and (> (current-column) 0)
366              (not (eq shr-state 'image)))
367     (insert "\n"))
368   (let ((start (point-marker)))
369     (let ((alt (cdr (assq :alt cont)))
370           (url (cdr (assq :src cont))))
371       (when (zerop (length alt))
372         (setq alt "[img]"))
373       (cond
374        ((and (not shr-inhibit-images)
375              (string-match "\\`cid:" url))
376         (let ((url (substring url (match-end 0)))
377               image)
378           (if (or (not shr-content-function)
379                   (not (setq image (funcall shr-content-function url))))
380               (insert alt)
381             (shr-put-image image (point) alt))))
382        ((or shr-inhibit-images
383             (and shr-blocked-images
384                  (string-match shr-blocked-images url)))
385         (setq shr-start (point))
386         (let ((shr-state 'space))
387           (if (> (length alt) 8)
388               (shr-insert (substring alt 0 8))
389             (shr-insert alt))))
390        ((url-is-cached (browse-url-url-encode-chars url "[&)$ ]"))
391         (shr-put-image (shr-get-image-data url) (point) alt))
392        (t
393         (insert alt)
394         (ignore-errors
395           (url-retrieve url 'shr-image-fetched
396                         (list (current-buffer) start (point-marker))
397                         t))))
398       (insert " ")
399       (put-text-property start (point) 'keymap shr-map)
400       (put-text-property start (point) 'shr-alt alt)
401       (put-text-property start (point) 'shr-image url)
402       (setq shr-state 'image))))
403
404 (defun shr-tag-pre (cont)
405   (let ((shr-folding-mode 'none))
406     (shr-ensure-newline)
407     (shr-generic cont)
408     (shr-ensure-newline)))
409
410 (defun shr-tag-blockquote (cont)
411   (shr-ensure-paragraph)
412   (let ((shr-indentation (+ shr-indentation 4)))
413     (shr-generic cont))
414   (shr-ensure-paragraph))
415
416 (defun shr-tag-ul (cont)
417   (shr-ensure-paragraph)
418   (let ((shr-list-mode 'ul))
419     (shr-generic cont))
420   (shr-ensure-paragraph))
421
422 (defun shr-tag-ol (cont)
423   (shr-ensure-paragraph)
424   (let ((shr-list-mode 1))
425     (shr-generic cont))
426   (shr-ensure-paragraph))
427
428 (defun shr-tag-li (cont)
429   (shr-ensure-newline)
430   (let* ((bullet
431           (if (numberp shr-list-mode)
432               (prog1
433                   (format "%d " shr-list-mode)
434                 (setq shr-list-mode (1+ shr-list-mode)))
435             "* "))
436          (shr-indentation (+ shr-indentation (length bullet))))
437     (insert bullet)
438     (shr-generic cont)))
439
440 (defun shr-tag-br (cont)
441   (unless (bobp)
442     (insert "\n"))
443   (shr-generic cont))
444
445 (defun shr-tag-h1 (cont)
446   (shr-heading cont 'bold 'underline))
447
448 (defun shr-tag-h2 (cont)
449   (shr-heading cont 'bold))
450
451 (defun shr-tag-h3 (cont)
452   (shr-heading cont 'italic))
453
454 (defun shr-tag-h4 (cont)
455   (shr-heading cont))
456
457 (defun shr-tag-h5 (cont)
458   (shr-heading cont))
459
460 (defun shr-tag-h6 (cont)
461   (shr-heading cont))
462
463 (defun shr-tag-hr (cont)
464   (shr-ensure-newline)
465   (insert (make-string shr-width ?-) "\n"))
466
467 ;;; Table rendering algorithm.
468
469 ;; Table rendering is the only complicated thing here.  We do this by
470 ;; first counting how many TDs there are in each TR, and registering
471 ;; how wide they think they should be ("width=45%", etc).  Then we
472 ;; render each TD separately (this is done in temporary buffers, so
473 ;; that we can use all the rendering machinery as if we were in the
474 ;; main buffer).  Now we know how much space each TD really takes, so
475 ;; we then render everything again with the new widths, and finally
476 ;; insert all these boxes into the main buffer.
477 (defun shr-tag-table (cont)
478   (shr-ensure-paragraph)
479   (setq cont (or (cdr (assq 'tbody cont))
480                  cont))
481   (let* ((shr-inhibit-images t)
482          ;; Find all suggested widths.
483          (columns (shr-column-specs cont))
484          ;; Compute how many characters wide each TD should be.
485          (suggested-widths (shr-pro-rate-columns columns))
486          ;; Do a "test rendering" to see how big each TD is (this can
487          ;; be smaller (if there's little text) or bigger (if there's
488          ;; unbreakable text).
489          (sketch (shr-make-table cont suggested-widths))
490          (sketch-widths (shr-table-widths sketch suggested-widths)))
491     ;; Then render the table again with these new "hard" widths.
492     (shr-insert-table (shr-make-table cont sketch-widths t) sketch-widths))
493   ;; Finally, insert all the images after the table.  The Emacs buffer
494   ;; model isn't strong enough to allow us to put the images actually
495   ;; into the tables.
496   (dolist (elem (shr-find-elements cont 'img))
497     (shr-tag-img (cdr elem))))
498
499 (defun shr-find-elements (cont type)
500   (let (result)
501     (dolist (elem cont)
502       (cond ((eq (car elem) type)
503              (push elem result))
504             ((consp (cdr elem))
505              (setq result (nconc (shr-find-elements (cdr elem) type) result)))))
506     (nreverse result)))
507
508 (defun shr-insert-table (table widths)
509   (shr-insert-table-ruler widths)
510   (dolist (row table)
511     (let ((start (point))
512           (height (let ((max 0))
513                     (dolist (column row)
514                       (setq max (max max (cadr column))))
515                     max)))
516       (dotimes (i height)
517         (shr-indent)
518         (insert "|\n"))
519       (dolist (column row)
520         (goto-char start)
521         (let ((lines (nth 2 column))
522               (overlay-lines (nth 3 column))
523               overlay overlay-line)
524           (dolist (line lines)
525             (setq overlay-line (pop overlay-lines))
526             (end-of-line)
527             (insert line "|")
528             (dolist (overlay overlay-line)
529               (let ((o (make-overlay (- (point) (nth 0 overlay) 1)
530                                      (- (point) (nth 1 overlay) 1)))
531                     (properties (nth 2 overlay)))
532                 (while properties
533                   (overlay-put o (pop properties) (pop properties)))))
534             (forward-line 1))
535           ;; Add blank lines at padding at the bottom of the TD,
536           ;; possibly.
537           (dotimes (i (- height (length lines)))
538             (end-of-line)
539             (insert (make-string (length (car lines)) ? ) "|")
540             (forward-line 1)))))
541     (shr-insert-table-ruler widths)))
542
543 (defun shr-insert-table-ruler (widths)
544   (shr-indent)
545   (insert shr-table-corner)
546   (dotimes (i (length widths))
547     (insert (make-string (aref widths i) shr-table-line) shr-table-corner))
548   (insert "\n"))
549
550 (defun shr-table-widths (table suggested-widths)
551   (let* ((length (length suggested-widths))
552          (widths (make-vector length 0))
553          (natural-widths (make-vector length 0)))
554     (dolist (row table)
555       (let ((i 0))
556         (dolist (column row)
557           (aset widths i (max (aref widths i)
558                               (car column)))
559           (aset natural-widths i (max (aref natural-widths i)
560                                       (cadr column)))
561           (setq i (1+ i)))))
562     (let ((extra (- (apply '+ (append suggested-widths nil))
563                     (apply '+ (append widths nil))))
564           (expanded-columns 0))
565       (when (> extra 0)
566         (dotimes (i length)
567           ;; If the natural width is wider than the rendered width, we
568           ;; want to allow the column to expand.
569           (when (> (aref natural-widths i) (aref widths i))
570             (setq expanded-columns (1+ expanded-columns))))
571         (dotimes (i length)
572           (when (> (aref natural-widths i) (aref widths i))
573             (aset widths i (min
574                             (1+ (aref natural-widths i))
575                             (+ (/ extra expanded-columns)
576                                (aref widths i))))))))
577     widths))
578
579 (defun shr-make-table (cont widths &optional fill)
580   (let ((trs nil))
581     (dolist (row cont)
582       (when (eq (car row) 'tr)
583         (let ((tds nil)
584               (columns (cdr row))
585               (i 0)
586               column)
587           (while (< i (length widths))
588             (setq column (pop columns))
589             (when (or (memq (car column) '(td th))
590                       (null column))
591               (push (shr-render-td (cdr column) (aref widths i) fill)
592                     tds)
593               (setq i (1+ i))))
594           (push (nreverse tds) trs))))
595     (nreverse trs)))
596
597 (defun shr-render-td (cont width fill)
598   (with-temp-buffer
599     (let ((cache (cdr (assoc (cons width cont) shr-content-cache))))
600       (if cache
601           (insert cache)
602         (let ((shr-width width)
603               (shr-indentation 0))
604           (shr-generic cont))
605         (delete-region
606          (point)
607          (+ (point)
608             (skip-chars-backward " \t\n")))
609         (push (cons (cons width cont) (buffer-string))
610               shr-content-cache)))
611     (goto-char (point-min))
612     (let ((max 0))
613       (while (not (eobp))
614         (end-of-line)
615         (setq max (max max (current-column)))
616         (forward-line 1))
617       (when fill
618         (goto-char (point-min))
619         ;; If the buffer is totally empty, then put a single blank
620         ;; line here.
621         (if (zerop (buffer-size))
622             (insert (make-string width ? ))
623           ;; Otherwise, fill the buffer.
624           (while (not (eobp))
625             (end-of-line)
626             (when (> (- width (current-column)) 0)
627               (insert (make-string (- width (current-column)) ? )))
628             (forward-line 1))))
629       (if fill
630           (list max
631                 (count-lines (point-min) (point-max))
632                 (split-string (buffer-string) "\n")
633                 (shr-collect-overlays))
634         (list max
635               (shr-natural-width))))))
636
637 (defun shr-natural-width ()
638   (goto-char (point-min))
639   (let ((current 0)
640         (max 0))
641     (while (not (eobp))
642       (end-of-line)
643       (setq current (+ current (current-column)))
644       (unless (get-text-property (point) 'shr-break)
645         (setq max (max max current)
646               current 0))
647       (forward-line 1))
648     max))
649
650 (defun shr-collect-overlays ()
651   (save-excursion
652     (goto-char (point-min))
653     (let ((overlays nil))
654       (while (not (eobp))
655         (push (shr-overlays-in-region (point) (line-end-position))
656               overlays)
657         (forward-line 1))
658       (nreverse overlays))))
659
660 (defun shr-overlays-in-region (start end)
661   (let (result)
662     (dolist (overlay (overlays-in start end))
663       (push (list (if (> start (overlay-start overlay))
664                       (- end start)
665                     (- end (overlay-start overlay)))
666                   (if (< end (overlay-end overlay))
667                       0
668                     (- end (overlay-end overlay)))
669                   (overlay-properties overlay))
670             result))
671     (nreverse result)))
672
673 (defun shr-pro-rate-columns (columns)
674   (let ((total-percentage 0)
675         (widths (make-vector (length columns) 0)))
676     (dotimes (i (length columns))
677       (setq total-percentage (+ total-percentage (aref columns i))))
678     (setq total-percentage (/ 1.0 total-percentage))
679     (dotimes (i (length columns))
680       (aset widths i (max (truncate (* (aref columns i)
681                                        total-percentage
682                                        (- shr-width (1+ (length columns)))))
683                           10)))
684     widths))
685
686 ;; Return a summary of the number and shape of the TDs in the table.
687 (defun shr-column-specs (cont)
688   (let ((columns (make-vector (shr-max-columns cont) 1)))
689     (dolist (row cont)
690       (when (eq (car row) 'tr)
691         (let ((i 0))
692           (dolist (column (cdr row))
693             (when (memq (car column) '(td th))
694               (let ((width (cdr (assq :width (cdr column)))))
695                 (when (and width
696                            (string-match "\\([0-9]+\\)%" width))
697                   (aset columns i
698                         (/ (string-to-number (match-string 1 width))
699                            100.0))))
700               (setq i (1+ i)))))))
701     columns))
702
703 (defun shr-count (cont elem)
704   (let ((i 0))
705     (dolist (sub cont)
706       (when (eq (car sub) elem)
707         (setq i (1+ i))))
708     i))
709
710 (defun shr-max-columns (cont)
711   (let ((max 0))
712     (dolist (row cont)
713       (when (eq (car row) 'tr)
714         (setq max (max max (+ (shr-count (cdr row) 'td)
715                               (shr-count (cdr row) 'th))))))
716     max))
717
718 (provide 'shr)
719
720 ;;; shr.el ends here