From 510da73b4a0ff77d27a208a4177ef21fcdbf766d Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Fri, 17 Jul 2020 03:13:05 +0200 Subject: [PATCH] Fix problems with not rendering shr tables with rowspan * lisp/net/shr.el (shr-max-columns): When rowspans were in effect, columns would go missing from subsequent lines (bug#42194). --- lisp/net/shr.el | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/lisp/net/shr.el b/lisp/net/shr.el index a3f04968a27..1ba615f92a8 100644 --- a/lisp/net/shr.el +++ b/lisp/net/shr.el @@ -2576,12 +2576,29 @@ flags that control whether to collect or render objects." i)) (defun shr-max-columns (dom) - (let ((max 0)) + (let ((max 0) + (this 0) + (rowspans nil)) (dolist (row (dom-children dom)) (when (and (not (stringp row)) (eq (dom-tag row) 'tr)) - (setq max (max max (+ (shr-count row 'td) - (shr-count row 'th)))))) + (setq this 0) + (dolist (column (dom-children row)) + (when (and (not (stringp column)) + (or (eq (dom-tag column) 'td) + (eq (dom-tag column) 'th))) + (setq this (+ (1+ this) (length rowspans))) + ;; We have a rowspan, which we emulate later in rendering + ;; by adding an extra column to the following rows. + (when-let* ((span (dom-attr column 'rowspan))) + (push (string-to-number span) rowspans)))) + (setq max (max max this))) + ;; Count down the rowspans in effect. + (let ((new nil)) + (dolist (span rowspans) + (when (> span 1) + (push (1- span) new))) + (setq rowspans new))) max)) (provide 'shr) -- 2.39.2