(shr-make-table-1): Make colspan display more sensibly.

This makes display of stuff like

 ---------- ---- ---- ----
|R1C1      |R1C2|R1C2|R1C2|
 ---------- ---- ---- ----
|R2C1 and R2C2  |RC4      |
|in one         |         |
 ---------- ---- ---- ----

work
parent 776705f4
......@@ -2,6 +2,7 @@
* net/shr.el (shr-make-table-1): Fix colspan typo.
(shr-make-table-1): Add comments.
(shr-make-table-1): Make colspan display more sensibly.
* net/eww.el (eww-add-bookmark): Fix prompt and clean up the code
slightly.
......
......@@ -1628,6 +1628,8 @@ The preference is a float determined from `shr-prefer-media-type'."
(let ((trs nil)
(shr-inhibit-decoration (not fill))
(rowspans (make-vector (length widths) 0))
(colspan-remaining 0)
colspan-width colspan-count
width colspan)
(dolist (row (dom-non-text-children dom))
(when (eq (dom-tag row) 'tr)
......@@ -1659,8 +1661,7 @@ The preference is a float determined from `shr-prefer-media-type'."
(if column
(aref widths width-column)
10))
(when (and fill
(setq colspan (dom-attr column 'colspan)))
(when (setq colspan (dom-attr column 'colspan))
(setq colspan (min (string-to-number colspan)
;; The colspan may be wrong, so
;; truncate it to the length of the
......@@ -1678,11 +1679,21 @@ The preference is a float determined from `shr-prefer-media-type'."
(+ width
shr-table-separator-length
(aref widths (+ i 1 j))))))
(setq width-column (+ width-column (1- colspan))))
(setq width-column (+ width-column (1- colspan))
colspan-count colspan
colspan-remaining colspan))
(when (or column
(not fill))
(push (shr-render-td column width fill)
tds))
(let ((data (shr-render-td column width fill)))
(if (and (not fill)
(> colspan-remaining 0))
(progn
(when (= colspan-count colspan-remaining)
(setq colspan-width data))
(let ((this-width (/ colspan-width colspan-count)))
(push this-width tds)
(setq colspan-remaining (1- colspan-remaining))))
(push data tds))))
(setq i (1+ i)
width-column (1+ width-column))))
(push (nreverse tds) trs))))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment