* Checking the type of an AST value?
@ 2019-05-13 4:48 Axel Rauschmayer
[not found] ` <7568353b-0873-4270-9450-3f97f0377ddd-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
0 siblings, 1 reply; 3+ messages in thread
From: Axel Rauschmayer @ 2019-05-13 4:48 UTC (permalink / raw)
To: pandoc-discuss
[-- Attachment #1.1: Type: text/plain, Size: 1229 bytes --]
My use case is similar to the following code (taken from pagebreak.lua in
the example repository):
-- Turning paragraphs which contain nothing but a form feed
-- characters into line breaks.
function Para (el)
if #el.content == 1 and el.content[1].text == '\f' then
return newpage(FORMAT)
end
end
Question: How do I check the type of an AST value? Here, it is done by
checking whether the value has the field .text (implying an instance of
pandoc.Str), but that doesn’t always work. A work-around would be to walk
the value and set a flag to true if a handler is invoked. But I was hoping
there is something simpler.
--
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 post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/7568353b-0873-4270-9450-3f97f0377ddd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
[-- Attachment #1.2: Type: text/html, Size: 2174 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Checking the type of an AST value?
[not found] ` <7568353b-0873-4270-9450-3f97f0377ddd-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-05-13 6:27 ` BPJ
[not found] ` <CADAJKhCdciC-kCBRdahv8agj2Fv_0Y1PUhFW4CnRAMCLVP8M6g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
0 siblings, 1 reply; 3+ messages in thread
From: BPJ @ 2019-05-13 6:27 UTC (permalink / raw)
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw
[-- Attachment #1: Type: text/plain, Size: 2358 bytes --]
You can check `element.t` (tag) like `if 'Str' == element.t`. It contains a
string equal to the element type name. It is also the best way to check
whether a table is an asset element: if it isn't `table.t` is most likely
`nil`.
Den mån 13 maj 2019 06:50Axel Rauschmayer <rauschma-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> skrev:
> My use case is similar to the following code (taken from pagebreak.lua in
> the example repository):
>
> -- Turning paragraphs which contain nothing but a form feed
> -- characters into line breaks.
> function Para (el)
> if #el.content == 1 and el.content[1].text == '\f' then
> return newpage(FORMAT)
> end
> end
>
> Question: How do I check the type of an AST value? Here, it is done by
> checking whether the value has the field .text (implying an instance of
> pandoc.Str), but that doesn’t always work. A work-around would be to walk
> the value and set a flag to true if a handler is invoked. But I was hoping
> there is something simpler.
>
> --
> 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 post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pandoc-discuss/7568353b-0873-4270-9450-3f97f0377ddd%40googlegroups.com
> <https://groups.google.com/d/msgid/pandoc-discuss/7568353b-0873-4270-9450-3f97f0377ddd%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
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 post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CADAJKhCdciC-kCBRdahv8agj2Fv_0Y1PUhFW4CnRAMCLVP8M6g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
[-- Attachment #2: Type: text/html, Size: 3898 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Checking the type of an AST value?
[not found] ` <CADAJKhCdciC-kCBRdahv8agj2Fv_0Y1PUhFW4CnRAMCLVP8M6g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2019-05-19 3:48 ` Axel Rauschmayer
0 siblings, 0 replies; 3+ messages in thread
From: Axel Rauschmayer @ 2019-05-19 3:48 UTC (permalink / raw)
To: pandoc-discuss
[-- Attachment #1.1: Type: text/plain, Size: 597 bytes --]
Thanks! Works perfectly.
--
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 post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/4c27d3d3-8653-4c48-94b0-daf07f42c08c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
[-- Attachment #1.2: Type: text/html, Size: 1009 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-05-19 3:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-13 4:48 Checking the type of an AST value? Axel Rauschmayer
[not found] ` <7568353b-0873-4270-9450-3f97f0377ddd-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-05-13 6:27 ` BPJ
[not found] ` <CADAJKhCdciC-kCBRdahv8agj2Fv_0Y1PUhFW4CnRAMCLVP8M6g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2019-05-19 3:48 ` Axel Rauschmayer
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).