* Lua filters: favoured method to check an element's class?
@ 2020-12-13 21:55 Julien Dutant
[not found] ` <4698b95d-02bd-49d0-80d0-7d1de555c0cfn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
0 siblings, 1 reply; 5+ messages in thread
From: Julien Dutant @ 2020-12-13 21:55 UTC (permalink / raw)
To: pandoc-discuss
[-- Attachment #1.1: Type: text/plain, Size: 1008 bytes --]
Hi all,
What's the favoured method to check an element's class in Lua filters? In
the manual a couple of examples use the following:
if element.classes[1]="myclass" then
But that's not robust if the element has several classes and `myclass` is
not the first:
::: {.otherclass .myclass}
I use a function that loops through the element.classes list (below). Have
I missed a more straightforward method?
function has_class(elem, str)
for _,class in pairs(elem.classes) do
if class == str then
return true
end
end
return false
end
if has_class(elem, "myclass") then ...
All best,
Julien
--
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/4698b95d-02bd-49d0-80d0-7d1de555c0cfn%40googlegroups.com.
[-- Attachment #1.2: Type: text/html, Size: 1834 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Lua filters: favoured method to check an element's class?
[not found] ` <4698b95d-02bd-49d0-80d0-7d1de555c0cfn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2020-12-13 22:17 ` Albert Krewinkel
[not found] ` <87zh2h8i71.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
0 siblings, 1 reply; 5+ messages in thread
From: Albert Krewinkel @ 2020-12-13 22:17 UTC (permalink / raw)
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw
Julien Dutant writes:
> What's the favoured method to check an element's class in Lua filters? In
> the manual a couple of examples use the following:
>
> if element.classes[1]="myclass" then
>
> But that's not robust if the element has several classes and `myclass` is
> not the first:
A convenient and robust check is `element.classes:includes 'myclass'`.
--
Albert Krewinkel
GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Lua filters: favoured method to check an element's class?
[not found] ` <87zh2h8i71.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
@ 2020-12-13 23:21 ` Julien Dutant
[not found] ` <eff82021-0b6e-4b66-bef9-55cc9ecc437an-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
0 siblings, 1 reply; 5+ messages in thread
From: Julien Dutant @ 2020-12-13 23:21 UTC (permalink / raw)
To: pandoc-discuss
[-- Attachment #1.1: Type: text/plain, Size: 1045 bytes --]
Ah thanks I wasn't sure when the methods in pandoc.List could be used.
Perfect!
J
On Sunday, December 13, 2020 at 10:17:18 PM UTC Albert Krewinkel wrote:
>
> Julien Dutant writes:
>
> > What's the favoured method to check an element's class in Lua filters?
> In
> > the manual a couple of examples use the following:
> >
> > if element.classes[1]="myclass" then
> >
> > But that's not robust if the element has several classes and `myclass`
> is
> > not the first:
>
> A convenient and robust check is `element.classes:includes 'myclass'`.
>
> --
> Albert Krewinkel
> GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124
>
--
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/eff82021-0b6e-4b66-bef9-55cc9ecc437an%40googlegroups.com.
[-- Attachment #1.2: Type: text/html, Size: 1674 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Lua filters: favoured method to check an element's class?
[not found] ` <eff82021-0b6e-4b66-bef9-55cc9ecc437an-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2020-12-14 10:00 ` BPJ
[not found] ` <CADAJKhCwR4xNTKioAovbBti97zb=A7MN7AC2q5_y-cTjGb0ofA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
0 siblings, 1 reply; 5+ messages in thread
From: BPJ @ 2020-12-14 10:00 UTC (permalink / raw)
To: pandoc-discuss
[-- Attachment #1: Type: text/plain, Size: 2447 bytes --]
If you want to know whether something is a table capable of doing some
known method you can generally do this:
``````lua
if 'table' == type(thing) then
if 'function' == type(thing.includes) then
io.stderr:write"A thing has a method 'includes'\n'"
end
end
``````
In the context of Lua filters you would typically put the above code in a
dummy global Pandoc function and run the "filter" with just
``````commandline
pandoc -L dummy.lua
<Ctrl-D>
``````
and if the test is successful you will see the message.
On Windows you would press <Ctrl-Z> rather than <Ctrl-D>.
--
Better --help|less than helpless
Den mån 14 dec. 2020 00:21Julien Dutant <julien.dutant-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> skrev:
> Ah thanks I wasn't sure when the methods in pandoc.List could be used.
> Perfect!
>
> J
>
> On Sunday, December 13, 2020 at 10:17:18 PM UTC Albert Krewinkel wrote:
>
>>
>> Julien Dutant writes:
>>
>> > What's the favoured method to check an element's class in Lua filters?
>> In
>> > the manual a couple of examples use the following:
>> >
>> > if element.classes[1]="myclass" then
>> >
>> > But that's not robust if the element has several classes and `myclass`
>> is
>> > not the first:
>>
>> A convenient and robust check is `element.classes:includes 'myclass'`.
>>
>> --
>> Albert Krewinkel
>> GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124
>>
> --
> 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/eff82021-0b6e-4b66-bef9-55cc9ecc437an%40googlegroups.com
> <https://groups.google.com/d/msgid/pandoc-discuss/eff82021-0b6e-4b66-bef9-55cc9ecc437an%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
--
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/CADAJKhCwR4xNTKioAovbBti97zb%3DA7MN7AC2q5_y-cTjGb0ofA%40mail.gmail.com.
[-- Attachment #2: Type: text/html, Size: 4044 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Lua filters: favoured method to check an element's class?
[not found] ` <CADAJKhCwR4xNTKioAovbBti97zb=A7MN7AC2q5_y-cTjGb0ofA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2020-12-14 23:20 ` Julien Dutant
0 siblings, 0 replies; 5+ messages in thread
From: Julien Dutant @ 2020-12-14 23:20 UTC (permalink / raw)
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw
[-- Attachment #1: Type: text/plain, Size: 3576 bytes --]
Nice, thanks!
On Mon, 14 Dec 2020 at 10:00, BPJ <melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> If you want to know whether something is a table capable of doing some
> known method you can generally do this:
>
> ``````lua
> if 'table' == type(thing) then
> if 'function' == type(thing.includes) then
> io.stderr:write"A thing has a method 'includes'\n'"
> end
> end
> ``````
>
> In the context of Lua filters you would typically put the above code in a
> dummy global Pandoc function and run the "filter" with just
>
> ``````commandline
> pandoc -L dummy.lua
> <Ctrl-D>
> ``````
>
> and if the test is successful you will see the message.
>
> On Windows you would press <Ctrl-Z> rather than <Ctrl-D>.
>
> --
> Better --help|less than helpless
>
> Den mån 14 dec. 2020 00:21Julien Dutant <julien.dutant-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> skrev:
>
>> Ah thanks I wasn't sure when the methods in pandoc.List could be used.
>> Perfect!
>>
>> J
>>
>> On Sunday, December 13, 2020 at 10:17:18 PM UTC Albert Krewinkel wrote:
>>
>>>
>>> Julien Dutant writes:
>>>
>>> > What's the favoured method to check an element's class in Lua filters?
>>> In
>>> > the manual a couple of examples use the following:
>>> >
>>> > if element.classes[1]="myclass" then
>>> >
>>> > But that's not robust if the element has several classes and `myclass`
>>> is
>>> > not the first:
>>>
>>> A convenient and robust check is `element.classes:includes 'myclass'`.
>>>
>>> --
>>> Albert Krewinkel
>>> GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124
>>>
>> --
>> 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/eff82021-0b6e-4b66-bef9-55cc9ecc437an%40googlegroups.com
>> <https://groups.google.com/d/msgid/pandoc-discuss/eff82021-0b6e-4b66-bef9-55cc9ecc437an%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> 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/iNOopSMIZ1k/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/CADAJKhCwR4xNTKioAovbBti97zb%3DA7MN7AC2q5_y-cTjGb0ofA%40mail.gmail.com
> <https://groups.google.com/d/msgid/pandoc-discuss/CADAJKhCwR4xNTKioAovbBti97zb%3DA7MN7AC2q5_y-cTjGb0ofA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
--
julien dutant
Department of Philosophy, King's College London
julien.dutant-3vygKqVCdQxaa/9Udqfwiw@public.gmane.org
http://julien.dutant.free.fr/
Strand
London WC2R 2LS
United Kingdom
--
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/CAN8rmZbYjM-vH9mptxOUPuN35PggVXj8XFM8BgezVegHzcRpDQ%40mail.gmail.com.
[-- Attachment #2: Type: text/html, Size: 7136 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-12-14 23:20 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-13 21:55 Lua filters: favoured method to check an element's class? Julien Dutant
[not found] ` <4698b95d-02bd-49d0-80d0-7d1de555c0cfn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2020-12-13 22:17 ` Albert Krewinkel
[not found] ` <87zh2h8i71.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2020-12-13 23:21 ` Julien Dutant
[not found] ` <eff82021-0b6e-4b66-bef9-55cc9ecc437an-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2020-12-14 10:00 ` BPJ
[not found] ` <CADAJKhCwR4xNTKioAovbBti97zb=A7MN7AC2q5_y-cTjGb0ofA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2020-12-14 23:20 ` Julien Dutant
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).