One way is to make several several passes. In the first pass you wrap all Cite elements in Span elements with a class which does not otherwise occur. In the second pass you visit Note elements and use `walk_block` to again unwrap those Span elements inside footnotes. In the third pass you use Inlines to find those Span elements elsewhere, unwrap them and adjust punctuation around the Cite. You make a multi-pass filter script by returning an array table with several filter map tables from the script. ``````lua local function wrap_cite (cite) return pandoc.Span({cite}, {class = 'is-cite'}) end local function unwrap_cite (span) if span.classes:includes('is-cite') then return span.content[1] return nil end local unwrap_filter = { Span = unwrap_cite } local function unwrap_in_notes (note) local old_blocks = pandoc.Div(note.content) local new_blocks = pandoc.walk_block(old_blocks, unwrap_filter) return pandoc.Note(new_blocks.content) end end local function adjust_punct (inlines) for i=1, #inlines do if 'Span' == inlines[i].tag then local cite = unwrap_cite(inlines[i]) if cite then -- move stuff around! end end end return inlines end return { { Cite = wrap_cite }, { Note = unwrap_in_notes }, { Inlines = adjust_punct }, } `````` Den tors 25 nov. 2021 20:02FI Apps skrev: > The particular case I’m dealing with is fixing a long and complex text > that followed an Italian style in placing punctuation after footnotes, even > though the text is in English. The script is a one-off, but since there are > over 1000 footnotes, fixing it with a script is the easiest solution. Since > I’m using BibLaTeX, I could tell it to move punctuation for footnotes > generated with Cite, but it just swaps the footnote and the punctuation: it > doesn’t move periods or commas into quotes that may precede the footnote. > > The first time I wrote a script that needed to know if it was in a > footnote, I resorted to the solution you suggest: I wrote a filter function > for Note and used walk_block. But since this is the second script that > wants to know whether or not it’s in a footnote, I thought I should mention > this as a desideratum for the future. > > > On 24 Nov 2021, at 18:59, John MacFarlane wrote: > > > > > > This is a limitation of the current architecture -- there's no > > way to determine the "parent" context. Sometimes you can work > > around this by using walk_block to do a transformation inside > > a particular kind of block (e.g. a footnote) -- but in this > > case you want to do the transformation OUTSIDE of the block, > > and that's more difficult. > > > > Doesn't pandoc's --citeproc do this punctuation moving for you > > (in the case of citations automatically added as footnotes)? > > If not, try setting `notes-after-punctuation` as described in > > the manual. > > > > (If you are talking about footnotoes you insert explicitly, > > instead of citations that become footnotes, then this doesn't > > apply, but in that case why would you need to adjust the > > punctuation?) > > > > jcr writes: > > > >> I find in Lua filters that I sometimes would like to know whether or > not > >> I'm in a footnote. Currently, I'm trying to move punctuation before > >> footnotes. Given my citation style, I know that a Cite in body text > will > >> produce a footnote, while a Cite in a footnote will not. So I want to > move > >> punctuation before a Cite when it's not in a footnote. Since a filter > >> function for Inlines will descend into footnotes as well, there doesn't > >> seem to be any way to tell when the Cite is in a footnote. > >> > >> In this particular case, I can work around the limitation because any > Cite > >> in a footnote will either be the first element or will have a Space > before > >> it. So with that assumption, I can look for the last innermost element > >> before the Cite and check its type: if it's a Str, can append the > >> punctuation to it and delete the punctuation from where it was. if it's > a > >> Space, I do nothing, because I must be in a footnote. However, at least > in > >> the long term, I'd like to be able to tell whether or not I'm in a > footnote. > >> > >> -- > >> You received this message because you are subscribed to the Google > Groups "pandoc-discuss" group. > >> To unsubscribe from this group and stop receiving emails from it, send > an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > >> To view this discussion on the web visit > https://groups.google.com/d/msgid/pandoc-discuss/111b665a-1b7a-4856-bf37-d96780a07c24n%40googlegroups.com > . > > -- > You received this message because you are subscribed to the Google Groups > "pandoc-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit > https://groups.google.com/d/msgid/pandoc-discuss/F6A8DF67-F34E-4FF9-A7A2-CF451E96D683%40gmail.com > . > -- You received this message because you are subscribed to the Google Groups "pandoc-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CADAJKhByRxPwZOqgkfkV6ZoSFfBZhHHX52mpyB36_ShLR40Gyg%40mail.gmail.com.