diff --git a/ox-html-markdown-style-footnotes.el b/ox-html-markdown-style-footnotes.el index 64521f8..f5424c6 100644 --- a/ox-html-markdown-style-footnotes.el +++ b/ox-html-markdown-style-footnotes.el @@ -27,24 +27,24 @@ (defun org-html-markdown-style-footnotes--section (orig-fun info) (if org-html-markdown-style-footnotes (pcase (org-export-collect-footnote-definitions info) - (`nil nil) - (definitions - (format - (plist-get info :html-footnotes-section) - (org-html--translate "Footnotes" info) - (format - "
    \n%s
\n" - (mapconcat - (lambda (definition) - (pcase definition - (`(,n ,_ ,def) - (format - "
  • %s %s
  • \n" - n - (org-trim (org-export-data def info)) - (format "↩︎" n))))) - definitions - "\n"))))) + (`nil nil) + (definitions + (format + (plist-get info :html-footnotes-section) + (org-html--translate "Footnotes" info) + (format + "
      \n%s
    \n" + (mapconcat + (lambda (definition) + (pcase definition + (`(,n ,label ,def) + (format + "
  • %s %s
  • \n" + (or label n) + (org-trim (org-export-data def info)) + (format "↩︎" (or label n)))))) + definitions + "\n"))))) (funcall orig-fun info))) ;;;###autoload diff --git a/ox-html-markdown-style-footnotes.org b/ox-html-markdown-style-footnotes.org index d13736a..7a03e0c 100644 --- a/ox-html-markdown-style-footnotes.org +++ b/ox-html-markdown-style-footnotes.org @@ -109,7 +109,7 @@ This results in footnotes with support for multiple paragraphs, that work withou * Implementation -In [[https://git.savannah.gnu.org/cgit/emacs/org-mode.git/tree/lisp/ox-html.el?h=release_9.6.5#n1858][Org mode 9.6.5]], the ~org-html-footnote-section~ looks like this: +In [[https://cgit.git.savannah.gnu.org/cgit/emacs/org-mode.git/tree/lisp/ox-html.el?h=release_9.7.34#n1870][Org mode 9.7.34]] the ~org-html-footnote-section~ looks like this: #+headers: :noweb yes #+begin_src emacs-lisp @@ -127,7 +127,7 @@ In [[https://git.savannah.gnu.org/cgit/emacs/org-mode.git/tree/lisp/ox-html.el?h (mapconcat (lambda (definition) (pcase definition - (`(,n ,_ ,def) + (`(,n ,label ,def) <>))) definitions "\n")))))) @@ -138,12 +138,24 @@ The interesting part is executed for each footnote, and wraps each footnote in a #+name: footnote-definitions #+begin_src emacs-lisp + ;; 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.%d" n) + (format "fn.%s" (or label n)) n - (format " class=\"footnum\" href=\"#fnr.%d\" role=\"doc-backlink\"" n) + (format " class=\"footnum\" href=\"#fnr.%s\" role=\"doc-backlink\"" (or label n)) info)) (contents (org-trim (org-export-data def info)))) (format "
    %s %s
    \n" @@ -223,25 +235,25 @@ The updated copy is defined as ~org-html-markdown-style-footnotes--section~: #+begin_src emacs-lisp (defun org-html-markdown-style-footnotes--section (orig-fun info) (if org-html-markdown-style-footnotes - (pcase (org-export-collect-footnote-definitions info) - (`nil nil) - (definitions - (format - (plist-get info :html-footnotes-section) - (org-html--translate "Footnotes" info) - (format - "
      \n%s
    \n" - (mapconcat - (lambda (definition) - (pcase definition - (`(,n ,_ ,def) - (format - "
  • %s %s
  • \n" - n - (org-trim (org-export-data def info)) - (format "↩︎" n))))) - definitions - "\n"))))) + (pcase (org-export-collect-footnote-definitions info) + (`nil nil) + (definitions + (format + (plist-get info :html-footnotes-section) + (org-html--translate "Footnotes" info) + (format + "
      \n%s
    \n" + (mapconcat + (lambda (definition) + (pcase definition + (`(,n ,label ,def) + (format + "
  • %s %s
  • \n" + (or label n) + (org-trim (org-export-data def info)) + (format "↩︎" (or label n)))))) + definitions + "\n"))))) (funcall orig-fun info))) #+end_src diff --git a/test.el b/test.el index a770ce2..1ac910b 100644 --- a/test.el +++ b/test.el @@ -11,6 +11,16 @@ (with-current-buffer "*Org HTML Export*" (buffer-string)))) (org-html-markdown-style-footnotes-remove)) +(ert-deftest labeled-footnote-test () + (org-html-markdown-style-footnotes-add) + (find-file "test/fixtures/labeled-footnote.org") + (let ((org-html-markdown-style-footnotes t)) + (org-html-export-as-html)) + (should (string-match-p + "
      \n
    1. \nA footnote.\n

      \n\n

      \nWith a second paragraph.\n

      ↩︎
    2. \n
    " + (with-current-buffer "*Org HTML Export*" (buffer-string)))) + (org-html-markdown-style-footnotes-remove)) + (ert-deftest disabled-test () (org-html-markdown-style-footnotes-add) (find-file "test/fixtures/footnote.org") diff --git a/test/fixtures/labeled-footnote.org b/test/fixtures/labeled-footnote.org new file mode 100644 index 0000000..5aa35a5 --- /dev/null +++ b/test/fixtures/labeled-footnote.org @@ -0,0 +1,5 @@ +Hello, world![fn:labeled] + +[fn:labeled] A footnote. + +With a second paragraph.