]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix formatting of tables with thead/tfoot but no tbody
authorJD Smith <93749+jdtsmith@users.noreply.github.com>
Sat, 6 Jul 2024 13:22:33 +0000 (09:22 -0400)
committerEshel Yaron <me@eshelyaron.com>
Sun, 7 Jul 2024 13:17:00 +0000 (15:17 +0200)
Correctly handle formatting of tables containing thead and/or tfoot, but
without any tbody, to prevent including thead/tfoot content twice within
the table's derived body.
* lisp/net/shr.el (shr--fix-tbody): Omit 'thead' and 'tfoot' from
implicit body.  (Bug#71685)
* test/lisp/net/shr-resources/table.html:
* test/lisp/net/shr-resources/table.txt: New tests for table rendering.

(cherry picked from commit 9625e4af9946436cea6ba3f41f6c384634bcc999)

lisp/net/shr.el
test/lisp/net/shr-resources/table.html [new file with mode: 0644]
test/lisp/net/shr-resources/table.txt [new file with mode: 0644]

index ea3d8deeff88ae78422665133955d7a65f32006b..4ccd8a5a85ae35fad19e832a564df99b2e0b33f4 100644 (file)
@@ -2342,8 +2342,9 @@ See `outline-search-function' for BOUND, MOVE, BACKWARD and LOOKING-AT."
 (defun shr--fix-tbody (tbody)
   (nconc (list 'tbody (dom-attributes tbody))
          (cl-loop for child in (dom-children tbody)
-                  collect (if (or (stringp child)
-                                  (not (eq (dom-tag child) 'tr)))
+                 for tag = (and (not (stringp child)) (dom-tag child))
+                 unless (or (eq tag 'thead) (eq tag 'tfoot))
+                 collect (if (not (eq tag 'tr))
                               (list 'tr nil (list 'td nil child))
                             child))))
 
diff --git a/test/lisp/net/shr-resources/table.html b/test/lisp/net/shr-resources/table.html
new file mode 100644 (file)
index 0000000..c5e8875
--- /dev/null
@@ -0,0 +1,7 @@
+<table>
+<thead><tr><th>A</th><th>B</th></tr></thead>
+<tr><td>1</td><td>2</td></tr>
+<tr><td>3</td><td>4</td></tr>
+5678
+<tfoot><tr><th>A</th><th>B</th></tr></tfoot>
+</table>
diff --git a/test/lisp/net/shr-resources/table.txt b/test/lisp/net/shr-resources/table.txt
new file mode 100644 (file)
index 0000000..70939ef
--- /dev/null
@@ -0,0 +1,5 @@
+  A  B    
+  1  2    
+  3  4    
+  5678     
+  A  B