From 681db0934e55ae6c2971ccfbfd9de7c0828506c9 Mon Sep 17 00:00:00 2001 Message-Id: <681db0934e55ae6c2971ccfbfd9de7c0828506c9.1714119282.git.info@protesilaos.com> From: Protesilaos Stavrou Date: Fri, 26 Apr 2024 11:14:28 +0300 Subject: [PATCH] Provide option to use footnote label as the HTML anchor text * lisp/ox-html.el (org-html-footnote-use-label-for-anchor-text): Define new user option. (org-html-footnote-section, org-html-footnote-reference): Use the new option. --- lisp/ox-html.el | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index 0237e61..804a464 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -699,6 +699,17 @@ (defcustom org-html-footnote-separator ", " :group 'org-export-html :type 'string) +(defcustom org-html-footnote-use-label-for-anchor-text nil + "When non-nil, use the footnote label as the anchor text. +When nil, use the number of the footnote as the anchor text. + +- For footnotes, this is the format: [fn:LABEL]. +- For inline footnotes, it is this: [fn:LABEL: Some text]." + :group 'org-export-html + :version "30.1" + :package-version '(Org . "9.7") + :type 'boolean) + ;;;; Headline (defcustom org-html-toplevel-hlevel 2 @@ -1900,7 +1911,9 @@ (defun org-html-footnote-section (info) (if label (format "fn.%s" label) (format "fn.%d" n)) - n + (if (and org-html-footnote-use-label-for-anchor-text label) + label + n) (format " class=\"footnum\" href=\"#fnr.%s\" role=\"doc-backlink\"" (or label n)) info)) (contents (org-trim (org-export-data def info)))) @@ -2768,7 +2781,11 @@ (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.%s\" role=\"doc-backlink\"" (or label n)) info))))) + id + (if (and org-html-footnote-use-label-for-anchor-text label) + label + n) + (format " class=\"footref\" href=\"#fn.%s\" role=\"doc-backlink\"" (or label n)) info))))) ;;;; Headline -- 2.39.2