all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#71685: [PATCH] fix shr rendering in tables without tbody
@ 2024-06-20 19:15 JD Smith
  0 siblings, 0 replies; only message 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] only message in thread

only message in thread, other threads:[~2024-06-20 19:15 UTC | newest]

Thread overview: (only message) (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

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.