From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms1.migadu.com with LMTPS id uEm6AkheK2ajeQAAqHPOHw:P1 (envelope-from ) for ; Fri, 26 Apr 2024 09:56:56 +0200 Received: from aspmx1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id uEm6AkheK2ajeQAAqHPOHw (envelope-from ) for ; Fri, 26 Apr 2024 09:56:56 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=protesilaos.com header.s=gm1 header.b=UbQS4l8o; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1714118216; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=wRsmOr+4/9u+FxgRg9wmIcJD/nh9pbpE5Y+QvvQBFRI=; b=f3RsdHhLwV1ZqpUHQbKHxlqfhxO6c4PMnE4P+BMs4VVlBOHtwiAscoQNBUGLGp2s8XHWy1 MNw65KyOtZw5iJSG+8hQC5xJI7iJ5ltsjykFdQGu7WZLdpdXq8heo1xfL8KdhhZn3G4MBe SH4ZrNhtKMlZvx9N+dNyYYZOEgo1zhMPUdxDsA4PfVB6EuX8qVwXbYCR3g3jRLqcEXeEKl 1og4CtCEc5Xv1chtRqG1Qz3LLIGA/hfHvT0//r6SKpHEmeCZtbmRm/ku0tlQY3sseVSgrD QBTTTt/qnXKa5lhgYdhrnvyQCtz9Mkvx9lkenWVw/qe9fJ31qUeZreszfAMcBQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1714118216; a=rsa-sha256; cv=none; b=Uz/Iu79fHyiOOFCkDT9AP5UdRYU8KGdVHQV+6guARwRoV/KW2lQJ5ikb271bErClomegV6 ukMW5C+IwBOyQyAFIvXIPPS0Hm7ZmY11S2kXHpX4ZJsi7SEjD3HUYKl8gwik6jFkAZw6/f tRuXPsMKbR4MSn+gClexjSVSi0jkFLUv4NiM7QIErr4Dfddtl0x11X0oBhLAMXrD+L+o5+ BV1h9il/cY3WhRjBiBn2rftmauZZdJWTNTCUx8UaUtd85zNs2Ba/+ARkrxaSFOV+btwptL oTsI+LhgRWBlqRLRAMqK9JRsY4As3eDC66FHv2gQ0PnfU+Uw+Zp++GyIXCkgbg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=protesilaos.com header.s=gm1 header.b=UbQS4l8o; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=none Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 51D54353DB for ; Fri, 26 Apr 2024 09:56:55 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s0GR6-0007oX-5o; Fri, 26 Apr 2024 03:56:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s0GR4-0007nx-Jw for emacs-orgmode@gnu.org; Fri, 26 Apr 2024 03:55:58 -0400 Received: from relay7-d.mail.gandi.net ([217.70.183.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s0GR2-0007Fg-6B for emacs-orgmode@gnu.org; Fri, 26 Apr 2024 03:55:58 -0400 Received: by mail.gandi.net (Postfix) with ESMTPSA id 580B42000E; Fri, 26 Apr 2024 07:55:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protesilaos.com; s=gm1; t=1714118152; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=wRsmOr+4/9u+FxgRg9wmIcJD/nh9pbpE5Y+QvvQBFRI=; b=UbQS4l8o1tZpsrg8hAaAKFJeqlDifK9LHt7yWgxw/KnOzPNNxT2/ugnD7l3q3YyR/ktvVF ZZfp3osG4npbNpoVvrzWG2yyrP2LupIWXbIwIWSd+EJScmvy1kGesKoJZbCpE6lzpzTRCX JYQ4ZY6qbTi4ITjM931F1cC3468IJSDZjwTMnFGQHWS9RwPn9kpkPqLKcZjlbEXqk+lLlB J7+DgXYxP1eq0wt9yCkg41YwzvE1OdE1+QgWcJAiT49pfAocQ2GeJaWqwMbrA/1ppQZ0ht D/zBJWcohsE/giYDZCPrPg+2Sdd1VoQfGlOfBIj9SotqnJNJiOSnOkHl1PgotQ== From: Protesilaos Stavrou To: Ihor Radchenko Cc: emacs-orgmode@gnu.org Subject: Re: [BUG] HTML export does not preserve footnote label [9.6.15 (release_9.6.15 @ /usr/local/share/emacs/30.0.50/lisp/org/)] In-Reply-To: <871q79cqgf.fsf@localhost> References: <877chcyz36.fsf@protesilaos.com> <87o7anop4i.fsf@localhost> <87y19lfzwv.fsf@protesilaos.com> <875xwpe1c5.fsf@localhost> <875xwngiwx.fsf@protesilaos.com> <871q79cqgf.fsf@localhost> Date: Fri, 26 Apr 2024 10:55:50 +0300 Message-ID: <87cyqcv9q1.fsf@protesilaos.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-GND-Sasl: info@protesilaos.com Received-SPF: none client-ip=217.70.183.200; envelope-from=info@protesilaos.com; helo=relay7-d.mail.gandi.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -9.35 X-Spam-Score: -9.35 X-Migadu-Queue-Id: 51D54353DB X-Migadu-Scanner: mx12.migadu.com X-TUID: /Xxuyj99SWt4 --=-=-= Content-Type: text/plain > From: Ihor Radchenko > Date: Sat, 13 Apr 2024 14:00:48 +0000 > > Protesilaos Stavrou writes: > >> With regard to the disambiguation scheme, I am playing around with >> various scenaria to see how Org HTML export behaves. Using the >> following: >> ... >> This is test 2 1 >> ... >> This is test 3 1 >> >> Notice that the 100 in the ID is not incremented further. I guess this >> is something that can be worked on but, again, I think it is separate >> from the issue of using the label for the ID and HREF. >> >> Any thoughts? > > Duplicate IDs are against HTML spec: > https://softwareengineering.stackexchange.com/questions/127178/two-html-elements-with-same-id-attribute-how-bad-is-it-really > > So, this is a bug. Indeed! We can look into this separately. >>>> Though I should have clarified my intent earlier: the idea is to use the >>>> label as a fixed reference to the footnote, so that the link does not >>>> change between exports. This is the same principle as what we do with >>>> links to headings that have a CUSTOM_ID. >>>> >>>> As such, the anchor text can still be the way it is now as an >>>> automatically generated number sequence (^1, ^2, etc.), but the HTML >>>> "id" and "href" values will be constructed based on the label of the >>>> footnote, NOT its number in the sequence. > > See the attached tentative patch. > [... 144 lines elided] Thank you! I just tried it. I encountered two problems with it, which I am addressing with the two attached patches (feel free to modify as needed). In short: 1. The footnote definitions at the bottom of the file were still using the ordinal HTML id, which did not correspond to the href with the label. 2. If the file had a mixture of labeled and anonymous/unlabeled footnotes, then the export would break as it would be passing a nil value to 'string-to-number'. Please let me know how to proceed. -- Protesilaos Stavrou https://protesilaos.com --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Use-the-label-if-present-in-footnote-definition.patch >From 0fb81645aafb780116465e13758601ff1183e043 Mon Sep 17 00:00:00 2001 Message-Id: <0fb81645aafb780116465e13758601ff1183e043.1714117826.git.info@protesilaos.com> From: Protesilaos Stavrou Date: Fri, 26 Apr 2024 10:41:51 +0300 Subject: [PATCH 1/2] Use the label, if present, in footnote definition * lisp/ox-html.el (org-html-footnote-section): Account for a non-nil label value. --- lisp/ox-html.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index aa0f891..95ecb44 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -1896,7 +1896,9 @@ (defun org-html-footnote-section (info) (let ((inline? (not (org-element-map def org-element-all-elements #'identity nil t))) (anchor (org-html--anchor - (format "fn.%d" n) + (if label + (format "fn.%s" label) + (format "fn.%d" n)) n (format " class=\"footnum\" href=\"#fnr.%s\" role=\"doc-backlink\"" (or label n)) info)) -- 2.39.2 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0002-Guard-against-nil-label-value-for-footnotes.patch >From 112c5671e5f55ea1d9e5e9fb6dd647e6a739c9ac Mon Sep 17 00:00:00 2001 Message-Id: <112c5671e5f55ea1d9e5e9fb6dd647e6a739c9ac.1714117826.git.info@protesilaos.com> In-Reply-To: <0fb81645aafb780116465e13758601ff1183e043.1714117826.git.info@protesilaos.com> References: <0fb81645aafb780116465e13758601ff1183e043.1714117826.git.info@protesilaos.com> From: Protesilaos Stavrou Date: Fri, 26 Apr 2024 10:49:26 +0300 Subject: [PATCH 2/2] Guard against nil label value for footnotes * lisp/ox-html.el (org-html-footnote-section) (org-html-footnote-reference): Check if label is a string before passing it to 'string-to-number'. This fixes the case where we are exporting some footnotes with a label and some without a label. --- lisp/ox-html.el | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index 95ecb44..0237e61 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -1886,7 +1886,8 @@ (defun org-html-footnote-section (info) ;; - the footnotes are re-numbered by ;; `org-export-get-footnote-number'. If the label is not ;; a number, keep it. - (when (equal label (number-to-string (string-to-number label))) + (when (and (stringp label) + (equal label (number-to-string (string-to-number label)))) (setq label nil)) ;; `org-export-collect-footnote-definitions' can return ;; two kinds of footnote definitions: inline and blocks. @@ -2754,8 +2755,10 @@ (defun org-html-footnote-reference (footnote-reference _contents info) ;; the footnotes are re-numbered by ;; `org-export-get-footnote-number'. If the label is not a ;; number, keep it. - (label (if (equal label (number-to-string (string-to-number label))) - nil label)) + (label (if (and (stringp label) + (equal label (number-to-string (string-to-number label)))) + nil + label)) (id (format "fnr.%s%s" (or label n) (if (org-export-footnote-first-reference-p -- 2.39.2 --=-=-=--