1 ;;; shr.el --- Simple HTML Renderer
3 ;; Copyright (C) 2010 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
8 ;; This file is part of GNU Emacs.
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.
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.
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/>.
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.
33 (eval-when-compile (require 'cl
))
35 (unless (aref (char-category-set (make-char 'japanese-jisx0208
33 35)) ?
>)
36 (load "kinsoku" nil t
))
39 "Simple HTML Renderer"
42 (defcustom shr-max-image-proportion
0.9
43 "How big pictures displayed are in relation to the window they're in.
44 A value of 0.7 means that they are allowed to take up 70% of the
45 width and height of the window. If they are larger than this,
46 and Emacs supports it, then the images will be rescaled down to
52 (defcustom shr-blocked-images nil
53 "Images that have URLs matching this regexp will be blocked."
58 (defcustom shr-table-line ?-
59 "Character used to draw table line."
63 (defcustom shr-table-corner ?
+
64 "Character used to draw table corner."
68 (defcustom shr-hr-line ?-
69 "Character used to draw hr line."
73 (defcustom shr-width fill-column
74 "Frame width to use for rendering."
78 (defvar shr-content-function nil
79 "If bound, this should be a function that will return the content.
80 This is used for cid: URLs, and the function is called with the
81 cid: URL as the argument.")
83 ;;; Internal variables.
85 (defvar shr-folding-mode nil
)
86 (defvar shr-state nil
)
87 (defvar shr-start nil
)
88 (defvar shr-indentation
0)
89 (defvar shr-inhibit-images nil
)
90 (defvar shr-list-mode nil
)
91 (defvar shr-content-cache nil
)
92 (defvar shr-kinsoku-shorten nil
)
95 (let ((map (make-sparse-keymap)))
96 (define-key map
"a" 'shr-show-alt-text
)
97 (define-key map
"i" 'shr-browse-image
)
98 (define-key map
"I" 'shr-insert-image
)
99 (define-key map
"u" 'shr-copy-url
)
100 (define-key map
"v" 'shr-browse-url
)
101 (define-key map
"o" 'shr-save-contents
)
102 (define-key map
"\r" 'shr-browse-url
)
105 ;; Public functions and commands.
108 (defun shr-insert-document (dom)
109 (setq shr-content-cache nil
)
110 (let ((shr-state nil
)
112 (shr-descend (shr-transform-dom dom
))))
114 (defun shr-copy-url ()
115 "Copy the URL under point to the kill ring.
116 If called twice, then try to fetch the URL and see whether it
117 redirects somewhere else."
119 (let ((url (get-text-property (point) 'shr-url
)))
122 (message "No URL under point"))
123 ;; Resolve redirected URLs.
124 ((equal url
(car kill-ring
))
129 (eq (car a
) :redirect
))
132 (goto-char (point-min))
133 ;; Remove common tracking junk from the URL.
134 (when (re-search-forward ".utm_.*" nil t
)
135 (replace-match "" t t
))
136 (message "Copied %s" (buffer-string))
137 (copy-region-as-kill (point-min) (point-max)))))))
138 ;; Copy the URL to the kill ring.
142 (copy-region-as-kill (point-min) (point-max))
143 (message "Copied %s" url
))))))
145 (defun shr-show-alt-text ()
146 "Show the ALT text of the image under point."
148 (let ((text (get-text-property (point) 'shr-alt
)))
150 (message "No image under point")
151 (message "%s" text
))))
153 (defun shr-browse-image ()
154 "Browse the image under point."
156 (let ((url (get-text-property (point) 'shr-image
)))
158 (message "No image under point")
159 (message "Browsing %s..." url
)
162 (defun shr-insert-image ()
163 "Insert the image under point into the buffer."
165 (let ((url (get-text-property (point) 'shr-image
)))
167 (message "No image under point")
168 (message "Inserting %s..." url
)
169 (url-retrieve url
'shr-image-fetched
170 (list (current-buffer) (1- (point)) (point-marker))
173 ;;; Utility functions.
175 (defun shr-transform-dom (dom)
176 (let ((result (list (pop dom
))))
177 (dolist (arg (pop dom
))
178 (push (cons (intern (concat ":" (symbol-name (car arg
))) obarray
)
183 (push (cons :text sub
) result
)
184 (push (shr-transform-dom sub
) result
)))
187 (defun shr-descend (dom)
188 (let ((function (intern (concat "shr-tag-" (symbol-name (car dom
))) obarray
)))
189 (if (fboundp function
)
190 (funcall function
(cdr dom
))
191 (shr-generic (cdr dom
)))))
193 (defun shr-generic (cont)
196 ((eq (car sub
) :text
)
197 (shr-insert (cdr sub
)))
199 (shr-descend sub
)))))
201 (defun shr-insert (text)
202 (when (and (eq shr-state
'image
)
203 (not (string-match "\\`[ \t\n]+\\'" text
)))
205 (setq shr-state nil
))
207 ((eq shr-folding-mode
'none
)
210 (when (and (string-match "\\`[ \t\n]" text
)
212 (not (eq (char-after (1- (point))) ?
)))
214 (dolist (elem (split-string text
))
216 (> shr-indentation
0))
218 ;; The shr-start is a special variable that is used to pass
219 ;; upwards the first point in the buffer where the text really
222 (setq shr-start
(point)))
223 ;; No space is needed behind a wide character categorized as
224 ;; kinsoku-bol, between characters both categorized as nospace,
225 ;; or at the beginning of a line.
227 (when (and (eq (preceding-char) ?
)
228 (or (= (line-beginning-position) (1- (point)))
229 (and (aref fill-find-break-point-function-table
230 (setq prev
(char-after (- (point) 2))))
231 (aref (char-category-set prev
) ?
>))
232 (and (aref fill-nospace-between-words-table prev
)
233 (aref fill-nospace-between-words-table
237 (while (> (current-column) shr-width
)
239 (shr-find-fill-point)
240 (when (eq (preceding-char) ?
)
243 (put-text-property (1- (point)) (point) 'shr-break t
)
244 ;; No space is needed at the beginning of a line.
245 (when (eq (following-char) ?
)
247 (when (> shr-indentation
0)
251 (unless (string-match "[ \t\n]\\'" text
)
254 (defun shr-find-fill-point ()
255 (when (> (move-to-column shr-width
) shr-width
)
259 (or (setq failed
(= (current-column) shr-indentation
))
260 (eq (preceding-char) ?
)
261 (eq (following-char) ?
)
262 (aref fill-find-break-point-function-table
(preceding-char))))
265 ;; There's no breakable point, so we give it up.
268 (while (aref fill-find-break-point-function-table
(preceding-char))
272 ;; Don't put kinsoku-bol characters at the beginning of a line,
273 ;; or kinsoku-eol characters at the end of a line,
275 (if (or shr-kinsoku-shorten
276 (and (aref (char-category-set (preceding-char)) ?
<)
278 (setq count
(1- count
))
282 (>= (setq count
(1- count
)) 0)
283 (not (memq (preceding-char) (list ?\C-
@ ?
\n ?
)))
284 (or (aref (char-category-set (preceding-char)) ?
<)
285 (aref (char-category-set (following-char)) ?
>)))
287 (while (and (>= (setq count
(1- count
)) 0)
288 (aref (char-category-set (following-char)) ?
>))
290 (when (eq (following-char) ?
)
294 (defun shr-ensure-newline ()
295 (unless (zerop (current-column))
298 (defun shr-ensure-paragraph ()
300 (if (<= (current-column) shr-indentation
)
301 (unless (save-excursion
312 (when (> shr-indentation
0)
313 (insert (make-string shr-indentation ?
))))
315 (defun shr-fontize-cont (cont &rest types
)
319 (shr-add-font (or shr-start
(point)) (point) type
))))
321 ;; Add an overlay in the region, but avoid putting the font properties
322 ;; on blank text at the start of the line, and the newline at the end,
323 ;; to avoid ugliness.
324 (defun shr-add-font (start end type
)
327 (while (< (point) end
)
329 (skip-chars-forward " "))
330 (let ((overlay (make-overlay (point) (min (line-end-position) end
))))
331 (overlay-put overlay
'face type
))
332 (if (< (line-end-position) end
)
336 (defun shr-browse-url ()
337 "Browse the URL under point."
339 (let ((url (get-text-property (point) 'shr-url
)))
341 (message "No link under point")
344 (defun shr-save-contents (directory)
345 "Save the contents from URL in a file."
346 (interactive "DSave contents of URL to directory: ")
347 (let ((url (get-text-property (point) 'shr-url
)))
349 (message "No link under point")
350 (url-retrieve (shr-encode-url url
)
351 'shr-store-contents
(list url directory
)))))
353 (defun shr-store-contents (status url directory
)
354 (unless (plist-get status
:error
)
355 (when (or (search-forward "\n\n" nil t
)
356 (search-forward "\r\n\r\n" nil t
))
357 (write-region (point) (point-max)
358 (expand-file-name (file-name-nondirectory url
)
361 (defun shr-image-fetched (status buffer start end
)
362 (when (and (buffer-name buffer
)
363 (not (plist-get status
:error
)))
364 (url-store-in-cache (current-buffer))
365 (when (or (search-forward "\n\n" nil t
)
366 (search-forward "\r\n\r\n" nil t
))
367 (let ((data (buffer-substring (point) (point-max))))
368 (with-current-buffer buffer
369 (let ((alt (buffer-substring start end
))
370 (inhibit-read-only t
))
371 (delete-region start end
)
372 (shr-put-image data start alt
))))))
373 (kill-buffer (current-buffer)))
375 (defun shr-put-image (data point alt
)
376 (if (not (display-graphic-p))
378 (let ((image (ignore-errors
379 (shr-rescale-image data
))))
381 (put-image image point alt
)))))
383 (defun shr-rescale-image (data)
384 (if (or (not (fboundp 'imagemagick-types
))
385 (not (get-buffer-window (current-buffer))))
386 (create-image data nil t
)
387 (let* ((image (create-image data nil t
))
388 (size (image-size image t
))
391 (edges (window-inside-pixel-edges
392 (get-buffer-window (current-buffer))))
393 (window-width (truncate (* shr-max-image-proportion
394 (- (nth 2 edges
) (nth 0 edges
)))))
395 (window-height (truncate (* shr-max-image-proportion
396 (- (nth 3 edges
) (nth 1 edges
)))))
398 (when (> height window-height
)
399 (setq image
(or (create-image data
'imagemagick t
400 :height window-height
)
402 (setq size
(image-size image t
)))
403 (when (> (car size
) window-width
)
405 (create-image data
'imagemagick t
410 (defun shr-get-image-data (url)
411 "Get image data for URL.
412 Return a string with image data."
414 (mm-disable-multibyte)
416 (url-cache-extract (url-cache-create-filename (shr-encode-url url
)))
418 (when (or (search-forward "\n\n" nil t
)
419 (search-forward "\r\n\r\n" nil t
))
420 (buffer-substring (point) (point-max))))))
422 (defun shr-heading (cont &rest types
)
423 (shr-ensure-paragraph)
424 (apply #'shr-fontize-cont cont types
)
425 (shr-ensure-paragraph))
427 ;;; Tag-specific rendering rules.
429 (defun shr-tag-p (cont)
430 (shr-ensure-paragraph)
433 (shr-ensure-paragraph))
435 (defun shr-tag-b (cont)
436 (shr-fontize-cont cont
'bold
))
438 (defun shr-tag-i (cont)
439 (shr-fontize-cont cont
'italic
))
441 (defun shr-tag-em (cont)
442 (shr-fontize-cont cont
'bold
))
444 (defun shr-tag-strong (cont)
445 (shr-fontize-cont cont
'bold
))
447 (defun shr-tag-u (cont)
448 (shr-fontize-cont cont
'underline
))
450 (defun shr-tag-s (cont)
451 (shr-fontize-cont cont
'strike-through
))
453 (defun shr-tag-span (cont)
454 (let ((start (point))
455 (color (cdr (assq 'color
(shr-parse-style (cdr (assq :style cont
)))))))
458 (let ((overlay (make-overlay start
(point))))
459 (overlay-put overlay
'face
(cons 'foreground-color color
))))))
461 (defun shr-parse-style (style)
464 (dolist (elem (split-string style
";"))
466 (setq elem
(split-string elem
":"))
467 (when (and (car elem
)
469 (let ((name (replace-regexp-in-string "^ +\\| +$" "" (car elem
)))
470 (value (replace-regexp-in-string "^ +\\| +$" "" (cadr elem
))))
471 (push (cons (intern name obarray
)
476 (defun shr-tag-a (cont)
477 (let ((url (cdr (assq :href cont
)))
481 (widget-convert-button
482 'url-link
(or shr-start start
) (point)
486 (put-text-property (or shr-start start
) (point) 'shr-url url
)))
488 (defun shr-encode-url (url)
490 (browse-url-url-encode-chars url
"[)$ ]"))
492 (defun shr-tag-img (cont)
494 (cdr (assq :src cont
)))
495 (when (and (> (current-column) 0)
496 (not (eq shr-state
'image
)))
498 (let ((alt (cdr (assq :alt cont
)))
499 (url (cdr (assq :src cont
))))
500 (let ((start (point-marker)))
501 (when (zerop (length alt
))
504 ((and (not shr-inhibit-images
)
505 (string-match "\\`cid:" url
))
506 (let ((url (substring url
(match-end 0)))
508 (if (or (not shr-content-function
)
509 (not (setq image
(funcall shr-content-function url
))))
511 (shr-put-image image
(point) alt
))))
512 ((or shr-inhibit-images
513 (and shr-blocked-images
514 (string-match shr-blocked-images url
)))
515 (setq shr-start
(point))
516 (let ((shr-state 'space
))
517 (if (> (length alt
) 8)
518 (shr-insert (substring alt
0 8))
520 ((url-is-cached (shr-encode-url url
))
521 (shr-put-image (shr-get-image-data url
) (point) alt
))
525 (url-retrieve (shr-encode-url url
) 'shr-image-fetched
526 (list (current-buffer) start
(point-marker))
529 (put-text-property start
(point) 'keymap shr-map
)
530 (put-text-property start
(point) 'shr-alt alt
)
531 (put-text-property start
(point) 'shr-image url
)
532 (setq shr-state
'image
)))))
534 (defun shr-tag-pre (cont)
535 (let ((shr-folding-mode 'none
))
539 (shr-ensure-newline)))
541 (defun shr-tag-blockquote (cont)
542 (shr-ensure-paragraph)
544 (let ((shr-indentation (+ shr-indentation
4)))
546 (shr-ensure-paragraph))
548 (defun shr-tag-ul (cont)
549 (shr-ensure-paragraph)
550 (let ((shr-list-mode 'ul
))
552 (shr-ensure-paragraph))
554 (defun shr-tag-ol (cont)
555 (shr-ensure-paragraph)
556 (let ((shr-list-mode 1))
558 (shr-ensure-paragraph))
560 (defun shr-tag-li (cont)
561 (shr-ensure-paragraph)
564 (if (numberp shr-list-mode
)
566 (format "%d " shr-list-mode
)
567 (setq shr-list-mode
(1+ shr-list-mode
)))
569 (shr-indentation (+ shr-indentation
(length bullet
))))
573 (defun shr-tag-br (cont)
579 (defun shr-tag-h1 (cont)
580 (shr-heading cont
'bold
'underline
))
582 (defun shr-tag-h2 (cont)
583 (shr-heading cont
'bold
))
585 (defun shr-tag-h3 (cont)
586 (shr-heading cont
'italic
))
588 (defun shr-tag-h4 (cont)
591 (defun shr-tag-h5 (cont)
594 (defun shr-tag-h6 (cont)
597 (defun shr-tag-hr (cont)
599 (insert (make-string shr-width shr-hr-line
) "\n"))
601 ;;; Table rendering algorithm.
603 ;; Table rendering is the only complicated thing here. We do this by
604 ;; first counting how many TDs there are in each TR, and registering
605 ;; how wide they think they should be ("width=45%", etc). Then we
606 ;; render each TD separately (this is done in temporary buffers, so
607 ;; that we can use all the rendering machinery as if we were in the
608 ;; main buffer). Now we know how much space each TD really takes, so
609 ;; we then render everything again with the new widths, and finally
610 ;; insert all these boxes into the main buffer.
611 (defun shr-tag-table-1 (cont)
612 (setq cont
(or (cdr (assq 'tbody cont
))
614 (let* ((shr-inhibit-images t
)
615 (shr-kinsoku-shorten t
)
616 ;; Find all suggested widths.
617 (columns (shr-column-specs cont
))
618 ;; Compute how many characters wide each TD should be.
619 (suggested-widths (shr-pro-rate-columns columns
))
620 ;; Do a "test rendering" to see how big each TD is (this can
621 ;; be smaller (if there's little text) or bigger (if there's
622 ;; unbreakable text).
623 (sketch (shr-make-table cont suggested-widths
))
624 (sketch-widths (shr-table-widths sketch suggested-widths
)))
625 ;; This probably won't work very well.
626 (when (> (+ (loop for width across sketch-widths
630 (setq truncate-lines t
))
631 ;; Then render the table again with these new "hard" widths.
632 (shr-insert-table (shr-make-table cont sketch-widths t
) sketch-widths
))
633 ;; Finally, insert all the images after the table. The Emacs buffer
634 ;; model isn't strong enough to allow us to put the images actually
636 (dolist (elem (shr-find-elements cont
'img
))
637 (shr-tag-img (cdr elem
))))
639 (defun shr-tag-table (cont)
640 (shr-ensure-paragraph)
641 (let* ((caption (cdr (assq 'caption cont
)))
642 (header (cdr (assq 'thead cont
)))
643 (body (or (cdr (assq 'tbody cont
)) cont
))
644 (footer (cdr (assq 'tfoot cont
)))
645 (nheader (if header
(shr-max-columns header
)))
646 (nbody (if body
(shr-max-columns body
)))
647 (nfooter (if footer
(shr-max-columns footer
))))
650 (if caption
`((tr (td ,@caption
))))
653 ;; hader + body + footer
654 (if (= nheader nbody
)
655 (if (= nbody nfooter
)
656 `((tr (td (table (tbody ,@header
,@body
,@footer
)))))
657 (nconc `((tr (td (table (tbody ,@header
,@body
)))))
660 `((tr (td (table (tbody ,@footer
))))))))
661 (nconc `((tr (td (table (tbody ,@header
)))))
662 (if (= nbody nfooter
)
663 `((tr (td (table (tbody ,@body
,@footer
)))))
664 (nconc `((tr (td (table (tbody ,@body
)))))
667 `((tr (td (table (tbody ,@footer
))))))))))
669 (if (= nheader nbody
)
670 `((tr (td (table (tbody ,@header
,@body
)))))
672 `(,@header
(tr (td (table (tbody ,@body
)))))
673 `((tr (td (table (tbody ,@header
))))
674 (tr (td (table (tbody ,@body
))))))))
677 (if (= nbody nfooter
)
678 `((tr (td (table (tbody ,@body
,@footer
)))))
679 (nconc `((tr (td (table (tbody ,@body
)))))
682 `((tr (td (table (tbody ,@footer
))))))))
684 `((tr (td (table (tbody ,@body
)))))
687 (defun shr-find-elements (cont type
)
690 (cond ((eq (car elem
) type
)
693 (setq result
(nconc (shr-find-elements (cdr elem
) type
) result
)))))
696 (defun shr-insert-table (table widths
)
697 (shr-insert-table-ruler widths
)
699 (let ((start (point))
700 (height (let ((max 0))
702 (setq max
(max max
(cadr column
))))
709 (let ((lines (nth 2 column
))
710 (overlay-lines (nth 3 column
))
711 overlay overlay-line
)
713 (setq overlay-line
(pop overlay-lines
))
716 (dolist (overlay overlay-line
)
717 (let ((o (make-overlay (- (point) (nth 0 overlay
) 1)
718 (- (point) (nth 1 overlay
) 1)))
719 (properties (nth 2 overlay
)))
721 (overlay-put o
(pop properties
) (pop properties
)))))
723 ;; Add blank lines at padding at the bottom of the TD,
725 (dotimes (i (- height
(length lines
)))
727 (insert (make-string (string-width (car lines
)) ?
) "|")
729 (shr-insert-table-ruler widths
)))
731 (defun shr-insert-table-ruler (widths)
733 (> shr-indentation
0))
735 (insert shr-table-corner
)
736 (dotimes (i (length widths
))
737 (insert (make-string (aref widths i
) shr-table-line
) shr-table-corner
))
740 (defun shr-table-widths (table suggested-widths
)
741 (let* ((length (length suggested-widths
))
742 (widths (make-vector length
0))
743 (natural-widths (make-vector length
0)))
747 (aset widths i
(max (aref widths i
)
749 (aset natural-widths i
(max (aref natural-widths i
)
752 (let ((extra (- (apply '+ (append suggested-widths nil
))
753 (apply '+ (append widths nil
))))
754 (expanded-columns 0))
757 ;; If the natural width is wider than the rendered width, we
758 ;; want to allow the column to expand.
759 (when (> (aref natural-widths i
) (aref widths i
))
760 (setq expanded-columns
(1+ expanded-columns
))))
762 (when (> (aref natural-widths i
) (aref widths i
))
764 (1+ (aref natural-widths i
))
765 (+ (/ extra expanded-columns
)
766 (aref widths i
))))))))
769 (defun shr-make-table (cont widths
&optional fill
)
772 (when (eq (car row
) 'tr
)
777 (while (< i
(length widths
))
778 (setq column
(pop columns
))
779 (when (or (memq (car column
) '(td th
))
781 (push (shr-render-td (cdr column
) (aref widths i
) fill
)
784 (push (nreverse tds
) trs
))))
787 (defun shr-render-td (cont width fill
)
789 (let ((cache (cdr (assoc (cons width cont
) shr-content-cache
))))
792 (let ((shr-width width
)
798 (skip-chars-backward " \t\n")))
799 (push (cons (cons width cont
) (buffer-string))
801 (goto-char (point-min))
805 (setq max
(max max
(current-column)))
808 (goto-char (point-min))
809 ;; If the buffer is totally empty, then put a single blank
811 (if (zerop (buffer-size))
812 (insert (make-string width ?
))
813 ;; Otherwise, fill the buffer.
816 (when (> (- width
(current-column)) 0)
817 (insert (make-string (- width
(current-column)) ?
)))
821 (count-lines (point-min) (point-max))
822 (split-string (buffer-string) "\n")
823 (shr-collect-overlays))
825 (shr-natural-width))))))
827 (defun shr-natural-width ()
828 (goto-char (point-min))
833 (setq current
(+ current
(current-column)))
834 (unless (get-text-property (point) 'shr-break
)
835 (setq max
(max max current
)
840 (defun shr-collect-overlays ()
842 (goto-char (point-min))
843 (let ((overlays nil
))
845 (push (shr-overlays-in-region (point) (line-end-position))
848 (nreverse overlays
))))
850 (defun shr-overlays-in-region (start end
)
852 (dolist (overlay (overlays-in start end
))
853 (push (list (if (> start
(overlay-start overlay
))
855 (- end
(overlay-start overlay
)))
856 (if (< end
(overlay-end overlay
))
858 (- end
(overlay-end overlay
)))
859 (overlay-properties overlay
))
863 (defun shr-pro-rate-columns (columns)
864 (let ((total-percentage 0)
865 (widths (make-vector (length columns
) 0)))
866 (dotimes (i (length columns
))
867 (setq total-percentage
(+ total-percentage
(aref columns i
))))
868 (setq total-percentage
(/ 1.0 total-percentage
))
869 (dotimes (i (length columns
))
870 (aset widths i
(max (truncate (* (aref columns i
)
872 (- shr-width
(1+ (length columns
)))))
876 ;; Return a summary of the number and shape of the TDs in the table.
877 (defun shr-column-specs (cont)
878 (let ((columns (make-vector (shr-max-columns cont
) 1)))
880 (when (eq (car row
) 'tr
)
882 (dolist (column (cdr row
))
883 (when (memq (car column
) '(td th
))
884 (let ((width (cdr (assq :width
(cdr column
)))))
886 (string-match "\\([0-9]+\\)%" width
))
888 (/ (string-to-number (match-string 1 width
))
893 (defun shr-count (cont elem
)
896 (when (eq (car sub
) elem
)
900 (defun shr-max-columns (cont)
903 (when (eq (car row
) 'tr
)
904 (setq max
(max max
(+ (shr-count (cdr row
) 'td
)
905 (shr-count (cdr row
) 'th
))))))