From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ivan Shmakov Newsgroups: gmane.emacs.bugs Subject: bug#19444: shr-tag-table: the value passed to shr-tag-table-1 is not a DOM Date: Fri, 26 Dec 2014 17:27:53 +0000 Message-ID: <87fvc2fhie.fsf@violet.siamics.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1419614962 12787 80.91.229.3 (26 Dec 2014 17:29:22 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 26 Dec 2014 17:29:22 +0000 (UTC) To: 19444@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Dec 26 18:29:15 2014 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Y4YhO-0007Qy-A2 for geb-bug-gnu-emacs@m.gmane.org; Fri, 26 Dec 2014 18:29:14 +0100 Original-Received: from localhost ([::1]:54044 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y4YhN-00059B-8t for geb-bug-gnu-emacs@m.gmane.org; Fri, 26 Dec 2014 12:29:13 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59685) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y4YhI-00056R-Pv for bug-gnu-emacs@gnu.org; Fri, 26 Dec 2014 12:29:10 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y4YhE-0005OE-Ka for bug-gnu-emacs@gnu.org; Fri, 26 Dec 2014 12:29:08 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:49000) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y4YhC-0005O8-H9 for bug-gnu-emacs@gnu.org; Fri, 26 Dec 2014 12:29:04 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1Y4YhC-0007Xa-4w for bug-gnu-emacs@gnu.org; Fri, 26 Dec 2014 12:29:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Ivan Shmakov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 26 Dec 2014 17:29:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 19444 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: submit@debbugs.gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.141961488728916 (code B ref -1); Fri, 26 Dec 2014 17:29:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 26 Dec 2014 17:28:07 +0000 Original-Received: from localhost ([127.0.0.1]:58366 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Y4YgI-0007WJ-Oj for submit@debbugs.gnu.org; Fri, 26 Dec 2014 12:28:07 -0500 Original-Received: from fely.am-1.org ([78.47.74.50]:46283) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Y4YgF-0007W9-Qe for submit@debbugs.gnu.org; Fri, 26 Dec 2014 12:28:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=siamics.net; s=a2013295; h=Content-Type:MIME-Version:Message-ID:Date:Sender:Subject:To:From; bh=tlYiZ8gNx3K6pmDfWGd5bbcqaLBUDpcxbdXWqs7f4WE=; b=J1jYDlJ09DigiRn71/cKcJyxI24huwU1Py9U4/J1iZjwCMBKFjK+WasQkSW4eherxGrgiSF/p6RcCQVTD3tWpIlx28FncuPINFaDNnW80VjbVoTAydJ3kyaQ+cQ8Xb0aCiwj6oyZN2BOeevyJpkp7Cnyx1/6dQSbFSBPmxGPRR4=; Original-Received: from [2a02:2560:6d4:26ca::1:1d] (helo=violet.siamics.net) by fely.am-1.org with esmtps (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1Y4YgE-0006PP-1O for submit@debbugs.gnu.org; Fri, 26 Dec 2014 17:28:02 +0000 Original-Received: from localhost ([::1] helo=violet.siamics.net) by violet.siamics.net with esmtps (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1Y4Yg6-0004fz-Fg for submit@debbugs.gnu.org; Sat, 27 Dec 2014 00:27:54 +0700 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:97736 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Package: emacs As of 36c43e95de5e (2014-12-18 16:44:11 +0000), shr-tag-table fails to pass a valid DOM value to shr-tag-table-1 when the table contains a thead, tfoot, or caption element (or any combination thereof.) Consider, e. g.: (with-temp-buffer (mapcar (lambda (table) (erase-buffer) (let ((r (shr-tag-table table))) (cons r (buffer-string)))) '((table nil (thead nil (tr nil (th nil "Foo") (th nil "Bar"))) (tbody nil (tr nil (th nil "Baz") (th nil "Qux")))) (table nil (thead nil (tr nil (th nil "Foo") (th nil "Bar"))) (tr nil (th nil "Baz") (th nil "Qux"))) (table nil (tr nil (th nil "Foo") (th nil "Bar")) (tfoot nil (tr nil (th nil "Baz") (th nil "Qux")))) (table nil (caption nil "Hello, world!") (tr nil (th nil "Foo") (th nil "Bar")) (tr nil (th nil "Baz") (th nil "Qux"))) (table nil (tr nil (th nil "Foo") (th nil "Bar")) (tr nil (th nil "Baz") (th nil "Qux")))))) ; =E2=86=92 ((nil . "") (nil . "") (nil . "") (nil . "") ; (nil . " Foo Bar \n Baz Qux \n")) The reasons to this are twofold. First of all, shr-tag-table generally assumes that the value of header and footer locals (and body, =E2=80=93 if at least one of header, footer is non-nil) are lists of elements, while they are in fact DOM values: 1440 (defun shr-tag-table (dom) 1441 (shr-ensure-paragraph) 1442 (let* ((caption (dom-child-by-tag dom 'caption)) 1443 (header (dom-child-by-tag dom 'thead)) 1444 (body (or (dom-child-by-tag dom 'tbody) dom)) 1445 (footer (dom-child-by-tag dom 'tfoot)) Suppose that (thead nil (tr nil (th nil "Foo") (th nil "Bar"))) gets assigned to =E2=80=98header=E2=80=99, for instance. Now, at a later point, =E2=80=98header=E2=80=99 is assumed to hold a list = of elements instead, which are put into a new tbody element: 1469 (if (=3D nbody nfooter) 1470 `((tr (td (table (tbody ,@header ,@body ,@footer))))) 1471 (nconc `((tr (td (table (tbody ,@header ,@body))))) 1472 (if (=3D nfooter 1) 1473 footer 1474 `((tr (td (table (tbody ,@footer)))))))) The second reason behind this problem is that the above backquote templates by no means lead to valid DOM values! For example, the last template above should instead read: `((tr nil (td nil (table nil (tbody nil ,@footer))))) Please consider the patch MIMEd. * lisp/net/shr.el (shr-tag-table): Ensure that shr-tag-table-1 gets passed a valid DOM value for tables containing a thead, tfoot, or caption. FWIW, applying the change makes the example above give a more sensible result: ((nil . " Foo Bar \n Baz Qux \n") (nil . " Foo Bar \n Baz Qux \n") (nil . " Foo Bar \n Baz Qux \n") (nil . " Hello, world! \n Foo Bar \n Baz Qux \n") (nil . " Foo Bar \n Baz Qux \n")) PS. I also took the liberty of rearranging a chain of =E2=80=98if=E2=80=99= forms into a cond. Not that it makes a big difference, though. --=20 FSF associate member #7257 np. Hope =E2=80=93 Apocalyptica =E2=80=A6 3= 013 B6A0 230E 334A --=-=-= Content-Type: text/diff Content-Disposition: inline --- a/lisp/net/shr.el +++ b/lisp/net/shr.el @@ -1439,10 +1439,11 @@ defun shr-tag-table-1 (dom) (defun shr-tag-table (dom) (shr-ensure-paragraph) - (let* ((caption (dom-child-by-tag dom 'caption)) - (header (dom-child-by-tag dom 'thead)) - (body (or (dom-child-by-tag dom 'tbody) dom)) - (footer (dom-child-by-tag dom 'tfoot)) + (let* ((caption (dom-children (dom-child-by-tag dom 'caption))) + (header (dom-non-text-children (dom-child-by-tag dom 'thead))) + (body (dom-non-text-children (or (dom-child-by-tag dom 'tbody) + dom))) + (footer (dom-non-text-children (dom-child-by-tag dom 'tfoot))) (bgcolor (dom-attr dom 'bgcolor)) (start (point)) (shr-stylesheet (nconc (list (cons 'background-color bgcolor)) @@ -1461,42 +1462,62 @@ defun shr-tag-table (dom) ;; It's a real table, so render it. (shr-tag-table-1 (nconc - (if caption `((tr (td ,@caption)))) - (if header - (if footer - ;; header + body + footer - (if (= nheader nbody) - (if (= nbody nfooter) - `((tr (td (table (tbody ,@header ,@body ,@footer))))) - (nconc `((tr (td (table (tbody ,@header ,@body))))) - (if (= nfooter 1) - footer - `((tr (td (table (tbody ,@footer)))))))) - (nconc `((tr (td (table (tbody ,@header))))) - (if (= nbody nfooter) - `((tr (td (table (tbody ,@body ,@footer))))) - (nconc `((tr (td (table (tbody ,@body))))) - (if (= nfooter 1) - footer - `((tr (td (table (tbody ,@footer)))))))))) - ;; header + body - (if (= nheader nbody) - `((tr (td (table (tbody ,@header ,@body))))) - (if (= nheader 1) - `(,@header (tr (td (table (tbody ,@body))))) - `((tr (td (table (tbody ,@header)))) - (tr (td (table (tbody ,@body)))))))) - (if footer - ;; body + footer - (if (= nbody nfooter) - `((tr (td (table (tbody ,@body ,@footer))))) - (nconc `((tr (td (table (tbody ,@body))))) - (if (= nfooter 1) - footer - `((tr (td (table (tbody ,@footer)))))))) - (if caption - `((tr (td (table (tbody ,@body))))) - body)))))) + (list 'table nil) + (if caption `((tr nil (td nil ,@caption)))) + (cond (header + (if footer + ;; header + body + footer + (if (= nheader nbody) + (if (= nbody nfooter) + `((tr nil (td nil (table nil + (tbody nil ,@header + ,@body ,@footer))))) + (nconc `((tr nil (td nil (table nil + (tbody nil ,@header + ,@body))))) + (if (= nfooter 1) + footer + `((tr nil (td nil (table + nil (tbody + nil ,@footer)))))))) + (nconc `((tr nil (td nil (table nil (tbody + nil ,@header))))) + (if (= nbody nfooter) + `((tr nil (td nil (table + nil (tbody nil ,@body + ,@footer))))) + (nconc `((tr nil (td nil (table + nil (tbody nil + ,@body))))) + (if (= nfooter 1) + footer + `((tr nil (td nil (table + nil + (tbody + nil + ,@footer)))))))))) + ;; header + body + (if (= nheader nbody) + `((tr nil (td nil (table nil (tbody nil ,@header + ,@body))))) + (if (= nheader 1) + `(,@header (tr nil (td nil (table + nil (tbody nil ,@body))))) + `((tr nil (td nil (table nil (tbody nil ,@header)))) + (tr nil (td nil (table nil (tbody nil ,@body))))))))) + (footer + ;; body + footer + (if (= nbody nfooter) + `((tr nil (td nil (table + nil (tbody nil ,@body ,@footer))))) + (nconc `((tr nil (td nil (table nil (tbody nil ,@body))))) + (if (= nfooter 1) + footer + `((tr nil (td nil (table + nil (tbody nil ,@footer))))))))) + (caption + `((tr nil (td nil (table nil (tbody nil ,@body)))))) + (body))))) (when bgcolor (shr-colorize-region start (point) (cdr (assq 'color shr-stylesheet)) bgcolor)) --=-=-=--