[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Filter for HTML footnotes?
From: |
Juan Manuel Macías |
Subject: |
Re: Filter for HTML footnotes? |
Date: |
Sun, 06 Mar 2022 04:03:10 +0000 |
M. ‘quintus’ Gülker writes:
> I recently discovered export filters and found some useful applications
> for them. For instance, the scientific domain I work in (law) uses
> footnote citations, and in these footnotes we abbreviate some words
> which would otherwise be written out in ordinary text, like name
> particles. Since I use org-cite these footnotes are automatically
> generated. So what I did was to write a filter which abbreviates these
> words on export in footnotes. I added the filter function to both
> org-export-filter-footnote-definition-functions and
> org-export-filter-footnote-reference-functions and indeed, when I export
> to LaTeX or ODT it does its job just fine. However, when I export to
> HTML instead, it does not. When I looked at the text passed to the
> filter when exporting as HTML, it turned out what the function receives
> is not the content of the footnote, but only the markup for the footnote
> number. That came a bit by surprise.
> So, what is the correct way to target the content of a footnote in a
> filter across backends?
Hi,
I think a function for `org-export-filter-parse-tree-functions' would
work better here. For example, this function replaces "lorem ipsum" with
"foo" in all footnote definitions:
#+BIND: org-export-filter-parse-tree-functions (fnt-filter-replace)
#+begin_src emacs-lisp :exports results :results none
(defun fnt-filter-replace (tree backend info)
(org-element-map tree 'footnote-definition
(lambda (fnt)
(let* ((contents (org-element-interpret-data
(org-element-contents fnt)))
(contents-new (with-temp-buffer
(insert contents)
(save-excursion
(goto-char (point-min))
(while (re-search-forward "lorem ipsum" nil t)
(replace-match "foo" t nil)))
(org-element-parse-buffer))))
(apply #'org-element-set-contents
fnt
(list contents-new))))
info)
tree)
#+end_src
Best regards,
Juan Manuel