Function: shr-tag-table-1
shr-tag-table-1 is a byte-compiled function defined in shr.el.gz.
Signature
(shr-tag-table-1 DOM)
Source Code
;; Defined in /usr/src/emacs/lisp/net/shr.el.gz
;;; Table rendering algorithm.
;; Table rendering is the only complicated thing here. We do this by
;; first counting how many TDs there are in each TR, and registering
;; how wide they think they should be ("width=45%", etc). Then we
;; render each TD separately (this is done in temporary buffers, so
;; that we can use all the rendering machinery as if we were in the
;; main buffer). Now we know how much space each TD really takes, so
;; we then render everything again with the new widths, and finally
;; insert all these boxes into the main buffer.
(defun shr-tag-table-1 (dom)
(setq dom (or (dom-child-by-tag dom 'tbody) dom))
(let* ((shr-inhibit-images t)
(shr-table-depth (1+ shr-table-depth))
;; Fill hard in CJK languages.
(pixel-fill-respect-kinsoku nil)
;; Find all suggested widths.
(columns (shr-column-specs dom))
;; Compute how many pixels wide each TD should be.
(suggested-widths (shr-pro-rate-columns columns))
;; Do a "test rendering" to see how big each TD is (this can
;; be smaller (if there's little text) or bigger (if there's
;; unbreakable text).
(elems (or (dom-attr dom 'shr-suggested-widths)
(shr-make-table dom suggested-widths nil
'shr-suggested-widths)))
(sketch (cl-loop for line in elems
collect (mapcar #'car line)))
(natural (cl-loop for line in elems
collect (mapcar #'cdr line)))
(sketch-widths (shr-table-widths sketch natural suggested-widths)))
;; This probably won't work very well.
(when (> (+ (cl-loop for width across sketch-widths
summing (1+ width))
shr-indentation shr-table-separator-pixel-width)
(frame-width))
(setq truncate-lines t))
;; Then render the table again with these new "hard" widths.
(shr-insert-table (shr-make-table dom sketch-widths t) sketch-widths)))