From 82a29bfd24076300b1b06ba94372dd29868fc607 Mon Sep 17 00:00:00 2001 From: JD Smith <93749+jdtsmith@users.noreply.github.com> Date: Sat, 6 Jul 2024 09:22:33 -0400 Subject: [PATCH] Fix formatting of tables with thead/tfoot but no tbody 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 | 5 +++-- test/lisp/net/shr-resources/table.html | 7 +++++++ test/lisp/net/shr-resources/table.txt | 5 +++++ 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 test/lisp/net/shr-resources/table.html create mode 100644 test/lisp/net/shr-resources/table.txt diff --git a/lisp/net/shr.el b/lisp/net/shr.el index ea3d8deeff8..4ccd8a5a85a 100644 --- a/lisp/net/shr.el +++ b/lisp/net/shr.el @@ -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 index 00000000000..c5e8875ac91 --- /dev/null +++ b/test/lisp/net/shr-resources/table.html @@ -0,0 +1,7 @@ +
A | B |
---|---|
1 | 2 |
3 | 4 |
A | B |