public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* Detectiing footnotes in Lua scripts
@ 2021-11-24  9:49 jcr
       [not found] ` <111b665a-1b7a-4856-bf37-d96780a07c24n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: jcr @ 2021-11-24  9:49 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 1428 bytes --]

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.

[-- Attachment #1.2: Type: text/html, Size: 1745 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Detectiing footnotes in Lua scripts
       [not found] ` <111b665a-1b7a-4856-bf37-d96780a07c24n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2021-11-24 17:59   ` John MacFarlane
       [not found]     ` <m2y25dtoxb.fsf-jF64zX8BO0+FqBokazbCQ6OPv3vYUT2dxr7GGTnW70NeoWH0uzbU5w@public.gmane.org>
  2021-12-13 17:15   ` Albert Krewinkel
  1 sibling, 1 reply; 8+ messages in thread
From: John MacFarlane @ 2021-11-24 17:59 UTC (permalink / raw)
  To: jcr, pandoc-discuss


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 <ffi.appdev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Detectiing footnotes in Lua scripts
       [not found]     ` <m2y25dtoxb.fsf-jF64zX8BO0+FqBokazbCQ6OPv3vYUT2dxr7GGTnW70NeoWH0uzbU5w@public.gmane.org>
@ 2021-11-25 19:02       ` FI Apps
       [not found]         ` <F6A8DF67-F34E-4FF9-A7A2-CF451E96D683-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: FI Apps @ 2021-11-25 19:02 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

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 <jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org> 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 <ffi.appdev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Detectiing footnotes in Lua scripts
       [not found]         ` <F6A8DF67-F34E-4FF9-A7A2-CF451E96D683-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2021-11-30 20:50           ` BPJ
       [not found]             ` <CADAJKhByRxPwZOqgkfkV6ZoSFfBZhHHX52mpyB36_ShLR40Gyg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: BPJ @ 2021-11-30 20:50 UTC (permalink / raw)
  To: pandoc-discuss

[-- Attachment #1: Type: text/plain, Size: 5788 bytes --]

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 <ffi.appdev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 <jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org> 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 <ffi.appdev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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.

[-- Attachment #2: Type: text/html, Size: 8309 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Detectiing footnotes in Lua scripts
       [not found]             ` <CADAJKhByRxPwZOqgkfkV6ZoSFfBZhHHX52mpyB36_ShLR40Gyg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2021-12-02 18:58               ` ffi.appdev-Re5JQEeQqe8AvxtiuMwx3w
  0 siblings, 0 replies; 8+ messages in thread
From: ffi.appdev-Re5JQEeQqe8AvxtiuMwx3w @ 2021-12-02 18:58 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

[-- Attachment #1: Type: text/plain, Size: 6715 bytes --]

I appreciate this clever solution, and will keep it in mind for the future, but I hope some simpler way of identifying elements in footnotes will be available the next time I write a script that needs to know.

> On Nov 30, 2021, at 9:50 PM, BPJ <melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> 
> 
> 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 <ffi.appdev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 <jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org> 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 <ffi.appdev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 a topic in the Google Groups "pandoc-discuss" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/pandoc-discuss/4S38_f_-384/unsubscribe.
> To unsubscribe from this group and all its topics, 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.

-- 
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/EBA1C46A-D0D0-4AA5-B97E-29F1DB97AEEC%40gmail.com.

[-- Attachment #2: Type: text/html, Size: 9804 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Detectiing footnotes in Lua scripts
       [not found] ` <111b665a-1b7a-4856-bf37-d96780a07c24n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  2021-11-24 17:59   ` John MacFarlane
@ 2021-12-13 17:15   ` Albert Krewinkel
       [not found]     ` <87fsqwo28w.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
  1 sibling, 1 reply; 8+ messages in thread
From: Albert Krewinkel @ 2021-12-13 17:15 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw


jcr <ffi.appdev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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.
>
> [...] at least in the long term, I'd like to be able to tell whether
> or not I'm in a footnote.

We just committed code[^1] that will help with this: it is now possible
to let the filter traverse the document top-down (root to leaves), and
to prevent processing of all element children by using `false` as a
second return value.

To exclude footnote contents from being processed, one can now use

    traverse = 'topdown'

    function Note (n)
      return n, false
    end

If you want to apply a *separate* filter in footnotes, you can write

    traverse = 'topdown'
    function Note (n)
      return n:walk(my_footnote_filter), false
    end

You should be able to try the feature after downloading the next nightly
build, which should become available at around 09:00 UTC.

[^1]: See https://github.com/jgm/pandoc/pull/7751/files

--
Albert Krewinkel
GPG: 8eed e3e2 e8c5 6f18 81fe  e836 388d c0b2 1f63 1124


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Detectiing footnotes in Lua scripts
       [not found]     ` <87fsqwo28w.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
@ 2021-12-13 19:08       ` ffi.appdev-Re5JQEeQqe8AvxtiuMwx3w
       [not found]         ` <F8CB6356-E282-40D0-BCB6-36D0C8FAAF1C-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: ffi.appdev-Re5JQEeQqe8AvxtiuMwx3w @ 2021-12-13 19:08 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

[-- Attachment #1: Type: text/plain, Size: 3132 bytes --]

That sounds like a clever solution: it doesn't change the data model or require pandoc to marshal all the parents for possible access. I'll wait for the next release, though.

Looking at the PR, I spotted a typo on line 233 of doc/lua-filter.md: "be" should be deleted from "will be try the following filter functions".

I see that the documentation only illustrates how to not traverse footnotes. Should it also illustrate how to apply a separate filter? The walk() method is new to me.

> On Dec 13, 2021, at 6:15 PM, Albert Krewinkel <albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org> wrote:
> 
> 
> jcr <ffi.appdev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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.
>> 
>> [...] at least in the long term, I'd like to be able to tell whether
>> or not I'm in a footnote.
> 
> We just committed code[^1] that will help with this: it is now possible
> to let the filter traverse the document top-down (root to leaves), and
> to prevent processing of all element children by using `false` as a
> second return value.
> 
> To exclude footnote contents from being processed, one can now use
> 
>    traverse = 'topdown'
> 
>    function Note (n)
>      return n, false
>    end
> 
> If you want to apply a *separate* filter in footnotes, you can write
> 
>    traverse = 'topdown'
>    function Note (n)
>      return n:walk(my_footnote_filter), false
>    end
> 
> You should be able to try the feature after downloading the next nightly
> build, which should become available at around 09:00 UTC.
> 
> [^1]: See https://github.com/jgm/pandoc/pull/7751/files
> 
> --
> Albert Krewinkel
> GPG: 8eed e3e2 e8c5 6f18 81fe  e836 388d c0b2 1f63 1124
> 
> -- 
> You received this message because you are subscribed to a topic in the Google Groups "pandoc-discuss" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/pandoc-discuss/4S38_f_-384/unsubscribe.
> To unsubscribe from this group and all its topics, 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/87fsqwo28w.fsf%40zeitkraut.de.

-- 
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/F8CB6356-E282-40D0-BCB6-36D0C8FAAF1C%40gmail.com.

[-- Attachment #2: Type: text/html, Size: 5362 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Detectiing footnotes in Lua scripts
       [not found]         ` <F8CB6356-E282-40D0-BCB6-36D0C8FAAF1C-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2021-12-13 20:20           ` Albert Krewinkel
  0 siblings, 0 replies; 8+ messages in thread
From: Albert Krewinkel @ 2021-12-13 20:20 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw


ffi.appdev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org writes:

> Looking at the PR, I spotted a typo on line 233 of doc/lua-filter.md:
> "be" should be deleted from "will be try the following filter
> functions".

Thanks, fixed.

> I see that the documentation only illustrates how to not traverse
> footnotes. Should it also illustrate how to apply a separate filter?
> The walk() method is new to me.

Indeed, it *is* new. The `walk` methods are basically more convenient
variants of `pandoc.utils.walk_inline` and `pandoc.utils.walk_block`,
but are now available on Pandoc, Block, and Inline objects, as well as
on lists of blocks (Blocks) and lists of inlines (Inlines). The method
is documented in each of these types; here it is for Block values:
https://github.com/jgm/pandoc/blob/master/doc/lua-filters.md?plain=1#L916-L947

Examples using `walk` will include
<https://github.com/jgm/pandoc/blob/master/doc/lua-filters.md#counting-words-in-a-document>
and
<https://github.com/jgm/pandoc/blob/master/doc/lua-filters.md#modifying-pandocs-manualtxt-for-man-pages>

A good example to demo its use in combination with `traverse =
'topdown'` could be helpful.


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-12-13 20:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-24  9:49 Detectiing footnotes in Lua scripts jcr
     [not found] ` <111b665a-1b7a-4856-bf37-d96780a07c24n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2021-11-24 17:59   ` John MacFarlane
     [not found]     ` <m2y25dtoxb.fsf-jF64zX8BO0+FqBokazbCQ6OPv3vYUT2dxr7GGTnW70NeoWH0uzbU5w@public.gmane.org>
2021-11-25 19:02       ` FI Apps
     [not found]         ` <F6A8DF67-F34E-4FF9-A7A2-CF451E96D683-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2021-11-30 20:50           ` BPJ
     [not found]             ` <CADAJKhByRxPwZOqgkfkV6ZoSFfBZhHHX52mpyB36_ShLR40Gyg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2021-12-02 18:58               ` ffi.appdev-Re5JQEeQqe8AvxtiuMwx3w
2021-12-13 17:15   ` Albert Krewinkel
     [not found]     ` <87fsqwo28w.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2021-12-13 19:08       ` ffi.appdev-Re5JQEeQqe8AvxtiuMwx3w
     [not found]         ` <F8CB6356-E282-40D0-BCB6-36D0C8FAAF1C-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2021-12-13 20:20           ` Albert Krewinkel

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 NNTP newsgroup(s).