From: Protesilaos Stavrou <info@protesilaos.com>
To: Ihor Radchenko <yantar92@posteo.net>
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/)]
Date: Fri, 26 Apr 2024 10:55:50 +0300 [thread overview]
Message-ID: <87cyqcv9q1.fsf@protesilaos.com> (raw)
In-Reply-To: <871q79cqgf.fsf@localhost>
[-- Attachment #1: Type: text/plain, Size: 2139 bytes --]
> From: Ihor Radchenko <yantar92@posteo.net>
> Date: Sat, 13 Apr 2024 14:00:48 +0000
>
> Protesilaos Stavrou <info@protesilaos.com> 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 <sup><a id="fnr.1.100" class="footref" href="#fn.1" role="doc-backlink">1</a></sup>
>> ...
>> This is test 3 <sup><a id="fnr.1.100" class="footref" href="#fn.1" role="doc-backlink">1</a></sup>
>>
>> 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
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Use-the-label-if-present-in-footnote-definition.patch --]
[-- Type: text/x-diff, Size: 1056 bytes --]
From 0fb81645aafb780116465e13758601ff1183e043 Mon Sep 17 00:00:00 2001
Message-Id: <0fb81645aafb780116465e13758601ff1183e043.1714117826.git.info@protesilaos.com>
From: Protesilaos Stavrou <info@protesilaos.com>
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
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-Guard-against-nil-label-value-for-footnotes.patch --]
[-- Type: text/x-diff, Size: 2191 bytes --]
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 <info@protesilaos.com>
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
next prev parent reply other threads:[~2024-04-26 7:56 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-05 8:48 [BUG] HTML export does not preserve footnote label [9.6.15 (release_9.6.15 @ /usr/local/share/emacs/30.0.50/lisp/org/)] Protesilaos Stavrou
2024-04-05 14:33 ` Ihor Radchenko
2024-04-10 7:19 ` Protesilaos Stavrou
2024-04-10 14:31 ` Ihor Radchenko
2024-04-12 7:05 ` Protesilaos Stavrou
2024-04-13 14:00 ` Ihor Radchenko
2024-04-26 7:55 ` Protesilaos Stavrou [this message]
2024-04-26 8:17 ` Protesilaos Stavrou
2024-04-26 9:53 ` Max Nikulin
2024-05-03 6:59 ` Protesilaos Stavrou
2024-05-03 10:53 ` Max Nikulin
2024-05-03 11:14 ` Ihor Radchenko
2024-05-03 17:29 ` Max Nikulin
2024-04-28 10:37 ` Ihor Radchenko
2024-05-03 9:07 ` Protesilaos Stavrou
2024-05-03 11:28 ` Ihor Radchenko
2024-04-28 10:22 ` Ihor Radchenko
2024-05-03 7:00 ` Protesilaos Stavrou
2024-04-28 10:36 ` Ihor Radchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87cyqcv9q1.fsf@protesilaos.com \
--to=info@protesilaos.com \
--cc=emacs-orgmode@gnu.org \
--cc=yantar92@posteo.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.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).