emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Juan Manuel Macías" <maciaschain@posteo.net>
To: "M. ‘quintus’ Gülker" <post+orgmodeml@guelker.eu>
Cc: orgmode <emacs-orgmode@gnu.org>
Subject: Re: Filter for HTML footnotes?
Date: Sun, 06 Mar 2022 04:03:10 +0000	[thread overview]
Message-ID: <87czizu3r5.fsf@posteo.net> (raw)
In-Reply-To: <87k0d81k7z.fsf@guelker.eu> ("M. ‘quintus’ Gülker"'s message of "Sat, 05 Mar 2022 16:40:16 +0100")

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?


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)
				 (goto-char (point-min))
				 (while (re-search-forward "lorem ipsum" nil t)
				   (replace-match "foo" t nil)))
	  (apply #'org-element-set-contents
		 (list contents-new))))

Best regards,

Juan Manuel 

  reply	other threads:[~2022-03-06  4:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-05 15:40 Filter for HTML footnotes? M. ‘quintus’ Gülker
2022-03-06  4:03 ` Juan Manuel Macías [this message]
2022-03-08  7:40   ` Filter for HTML (cite) footnotes? M. ‘quintus’ Gülker
2022-03-08 10:14     ` Juan Manuel Macías
2023-01-07 17:12       ` M. ‘quintus’ Gülker

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:

  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=87czizu3r5.fsf@posteo.net \
    --to=maciaschain@posteo.net \
    --cc=emacs-orgmode@gnu.org \
    --cc=post+orgmodeml@guelker.eu \


* 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


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