unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#71685: [PATCH] fix shr rendering in tables without tbody
@ 2024-06-20 19:15 JD Smith
  2024-07-06  7:36 ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: JD Smith @ 2024-06-20 19:15 UTC (permalink / raw)
  To: 71685

[-- Attachment #1: Type: text/plain, Size: 1080 bytes --]

It is very common for HTML tables to include a header (<thead>) and/or footer (<tfoot>) without using <tbody>.  Modern browsers simply supply an implicit <tbody>..</tbody> around all the unparented rows in a table.  `shr' does not handle this common case correctly.  Below is an example with <thead> but not <tbody>.  It prints the header, but then subsumes it again inside the derived body, printing the header again in a single cell.  

The relevant function which should handle this is `shr--fix-tbody'.   The included patch to this function simply avoids including `thead` and `tfoot` children in the implicit body.

(let ((shr-table-vertical-line ?|)
      (shr-table-horizontal-line ?-))
  (shr-insert-document
   (with-temp-buffer
     (insert "<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>
</table>")
     (libxml-parse-html-region))))

 ---------  
| ---  --   |
||A |B | |
| ---  --   |
||AB | |
| ---  --   |
||1 |2 | |
| ---  --   |
||3 |4 | |
| ---  --   |
 ---------  



[-- Attachment #2: shr_fix_tbody.patch --]
[-- Type: application/octet-stream, Size: 595 bytes --]

--- shr.el	2024-06-20 15:03:52
+++ shr_fix_tbody.el	2024-06-20 15:00:49
@@ -2053,8 +2053,9 @@
 (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))))
 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-07-06 19:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-20 19:15 bug#71685: [PATCH] fix shr rendering in tables without tbody JD Smith
2024-07-06  7:36 ` Eli Zaretskii
2024-07-06 18:13   ` JD Smith
2024-07-06 19:11     ` Stefan Kangas

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).