Compare commits

...

2 Commits

Author SHA1 Message Date
Ihor Radchenko e0f24a3f6d
org-html-footnote-reference: Fix duplicate IDs
* lisp/ox-html.el (org-html-footnote-reference): When multiple
footnote references point to a single footnote, make sure that the
reference ids are not duplicated.  Now, the ids for non-first
reference are constructed as fn.<footnote id>.<footnote reference
number>.  The reference number of counted across all the footnote
references referencing the same footnote.

Reported-by: Protesilaos Stavrou <info@protesilaos.com>
Link: https://orgmode.org/list/87cyqcv9q1.fsf@protesilaos.com
2024-04-28 13:35:31 +03:00
Ihor Radchenko 065af4b42a
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

Co-authored-by: Protesilaos Stavrou <info@protesilaos.com>
2024-04-28 13:18:59 +03:00
2 changed files with 65 additions and 33 deletions

View File

@ -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.

View File

@ -1873,36 +1873,43 @@ INFO is a plist used as a communication channel."
(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 (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.
;; 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.%s" (or label 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"))))))
;;; Template
@ -2741,16 +2748,33 @@ CONTENTS is nil. INFO is a plist holding contextual information."
(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 (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
footnote-reference info)
""
".100"))))
(let ((label (org-element-property :label footnote-reference)))
(format
".%d"
(org-export-get-ordinal
footnote-reference info '(footnote-reference)
`(lambda (ref _)
(if ,label
(equal (org-element-property :label ref) ,label)
(not (org-element-property :label ref)))))))))))
(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