From: Ihor Radchenko <yantar92@posteo.net>
To: Protesilaos Stavrou <info@protesilaos.com>
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: Sat, 13 Apr 2024 14:00:48 +0000 [thread overview]
Message-ID: <871q79cqgf.fsf@localhost> (raw)
In-Reply-To: <875xwngiwx.fsf@protesilaos.com>
[-- Attachment #1: Type: text/plain, Size: 1394 bytes --]
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.
>>> 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.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-html-Use-non-number-footnote-names-as-link-anchor.patch --]
[-- Type: text/x-patch, Size: 5823 bytes --]
From 446bfc8c8afb5b2e09d0e0acf7b136b9f0780f5a Mon Sep 17 00:00:00 2001
Message-ID: <446bfc8c8afb5b2e09d0e0acf7b136b9f0780f5a.1713016519.git.yantar92@posteo.net>
From: Ihor Radchenko <yantar92@posteo.net>
Date: Sat, 13 Apr 2024 16:53:48 +0300
Subject: [PATCH] ox-html: Use non-number footnote names as link anchors
* lisp/ox-html.el (org-html-footnote-section):
* lisp/ox-html.el (org-html-footnote-reference): When footnote has a
non-number name, build link anchors using this name.
* etc/ORG-NEWS (=ox-html=: When exporting footnotes with custom
non-number names, the names are used as link anchors): Announce the
change.
Link: https://orgmode.org/list/875xwngiwx.fsf@protesilaos.com
---
etc/ORG-NEWS | 8 +++++
lisp/ox-html.el | 77 +++++++++++++++++++++++++++++--------------------
2 files changed, 53 insertions(+), 32 deletions(-)
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index e61bd6988..1b7040815 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -13,6 +13,14 @@ Please send Org bug reports to mailto:emacs-orgmode@gnu.org.
* Version 9.7 (not released yet)
** Important announcements and breaking changes
+*** =ox-html=: When exporting footnotes with custom non-number names, the names are used as link anchors
+
+Previously, link anchors for footnote references and footnote
+definitions were based on the footnote number: =fn.1=, =fnr.15=, etc.
+
+Now, when the footnote has a non-number name, it is used as an anchor:
+=fn.name=, =fnr.name=.
+
*** Underline syntax now takes priority over subscript when both are applicable
Previously, Org mode interpreted =(_text_)= as subscript.
diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index 0471a573b..1262da1aa 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -1873,36 +1873,42 @@ (defun org-html-footnote-section (info)
(pcase (org-export-collect-footnote-definitions info)
(`nil nil)
(definitions
+ (format
+ (plist-get info :html-footnotes-section)
+ (org-html--translate "Footnotes" info)
(format
- (plist-get info :html-footnotes-section)
- (org-html--translate "Footnotes" info)
- (format
- "\n%s\n"
- (mapconcat
- (lambda (definition)
- (pcase definition
- (`(,n ,_ ,def)
- ;; `org-export-collect-footnote-definitions' can return
- ;; two kinds of footnote definitions: inline and blocks.
- ;; Since this should not make any difference in the HTML
- ;; output, we wrap the inline definitions within
- ;; a "footpara" class paragraph.
- (let ((inline? (not (org-element-map def org-element-all-elements
- #'identity nil t)))
- (anchor (org-html--anchor
- (format "fn.%d" n)
- n
- (format " class=\"footnum\" href=\"#fnr.%d\" role=\"doc-backlink\"" n)
- info))
- (contents (org-trim (org-export-data def info))))
- (format "<div class=\"footdef\">%s %s</div>\n"
- (format (plist-get info :html-footnote-format) anchor)
- (format "<div class=\"footpara\" role=\"doc-footnote\">%s</div>"
- (if (not inline?) contents
- (format "<p class=\"footpara\">%s</p>"
- contents))))))))
- definitions
- "\n"))))))
+ "\n%s\n"
+ (mapconcat
+ (lambda (definition)
+ (pcase definition
+ (`(,n ,label ,def)
+ ;; Do not assign number labels as they appear in Org mode
+ ;; - 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)))
+ (setq label nil))
+ ;; `org-export-collect-footnote-definitions' can return
+ ;; two kinds of footnote definitions: inline and blocks.
+ ;; Since this should not make any difference in the HTML
+ ;; output, we wrap the inline definitions within
+ ;; a "footpara" class paragraph.
+ (let ((inline? (not (org-element-map def org-element-all-elements
+ #'identity nil t)))
+ (anchor (org-html--anchor
+ (format "fn.%d" n)
+ n
+ (format " class=\"footnum\" href=\"#fnr.%s\" role=\"doc-backlink\"" (or label n))
+ info))
+ (contents (org-trim (org-export-data def info))))
+ (format "<div class=\"footdef\">%s %s</div>\n"
+ (format (plist-get info :html-footnote-format) anchor)
+ (format "<div class=\"footpara\" role=\"doc-footnote\">%s</div>"
+ (if (not inline?) contents
+ (format "<p class=\"footpara\">%s</p>"
+ contents))))))))
+ definitions
+ "\n"))))))
\f
;;; Template
@@ -2736,8 +2742,15 @@ (defun org-html-footnote-reference (footnote-reference _contents info)
(when (org-element-type-p prev 'footnote-reference)
(plist-get info :html-footnote-separator)))
(let* ((n (org-export-get-footnote-number footnote-reference info))
- (id (format "fnr.%d%s"
- n
+ (label (org-element-property :label footnote-reference))
+ ;; Do not assign number labels as they appear in Org mode -
+ ;; 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))
+ (id (format "fnr.%s%s"
+ (or label n)
(if (org-export-footnote-first-reference-p
footnote-reference info)
""
@@ -2745,7 +2758,7 @@ (defun org-html-footnote-reference (footnote-reference _contents info)
(format
(plist-get info :html-footnote-format)
(org-html--anchor
- id n (format " class=\"footref\" href=\"#fn.%d\" role=\"doc-backlink\"" n) info)))))
+ id n (format " class=\"footref\" href=\"#fn.%s\" role=\"doc-backlink\"" (or label n)) info)))))
;;;; Headline
--
2.44.0
[-- Attachment #3: Type: text/plain, Size: 224 bytes --]
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
next prev parent reply other threads:[~2024-04-13 14:01 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 [this message]
2024-04-26 7:55 ` Protesilaos Stavrou
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=871q79cqgf.fsf@localhost \
--to=yantar92@posteo.net \
--cc=emacs-orgmode@gnu.org \
--cc=info@protesilaos.com \
/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).