emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] shr-fontified 1a369fc 2/3: (shr-make-table-1): Make colspa


From: Lars Ingebrigtsen
Subject: [Emacs-diffs] shr-fontified 1a369fc 2/3: (shr-make-table-1): Make colspan display more sensibly.
Date: Wed, 28 Jan 2015 02:22:58 +0000

branch: shr-fontified
commit 1a369fc7f1ccec6954344ec1ee0211a4d24c312d
Author: Lars Magne Ingebrigtsen <address@hidden>
Commit: Lars Magne Ingebrigtsen <address@hidden>

    (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
---
 lisp/ChangeLog  |    1 +
 lisp/net/shr.el |   21 ++++++++++++++++-----
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 1bb003c..d17dff2 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -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.
diff --git a/lisp/net/shr.el b/lisp/net/shr.el
index f4c765f..59c277b 100644
--- a/lisp/net/shr.el
+++ b/lisp/net/shr.el
@@ -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))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]