]> git.eshelyaron.com Git - emacs.git/commitdiff
(shr-make-table-1): Make colspan display more sensibly.
authorLars Magne Ingebrigtsen <larsi@gnus.org>
Mon, 26 Jan 2015 06:04:55 +0000 (17:04 +1100)
committerLars Magne Ingebrigtsen <larsi@gnus.org>
Mon, 26 Jan 2015 06:04:55 +0000 (17:04 +1100)
This makes display of stuff like

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

work

lisp/ChangeLog
lisp/net/shr.el

index 1bb003c9205cb02b6c2a28b7edf3e23a9afdd1bc..d17dff23a2f49e0419e941f46cab0de77cf45e12 100644 (file)
@@ -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.
index f4c765f4d25678d0d7ac51d0bd29d3b190917599..59c277b01c2cea8fcd902f1b6a3e3f07c954cf6a 100644 (file)
@@ -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))))