Great, thanks.
ThomasH <the...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
> I want to detect the types of the inline elements of a paragraph. I
> understand there is pandoc.utils.type() that basically does that, but
> when I run
>
> function Para(para)
> for i = 1,#para.content,1 do
> print(tostring(pandoc.utils.type(para.content[i])))
> end
> end
>
> all that is printed is "Inline" for all elements, not specific types
> like Str, Span, Link or Image. How can I get at the specific types?
The trick here is that we are using Haskell terminology: Inline is a
*type*, and Str, Span, Link, etc. are *constructors* for this type. In
Lua (and JSON) contexts, the property that identifies the name of the
constructor of a value is called a "tag". Try this:
``` lua
function Para(para)
for i = 1,#para.content do
print(para.content[i].tag))
end
end
```
The `.t` property is an alias for `.tag` and can be used as well.
I have plans to change the behavior of `pandoc.utils.type` and to make
the function return two results. The first result would stay as-is, with
the second result containing the constructor name. But I need to run
more tests to ensure that this won't lead to performance degradation.
--
Albert Krewinkel
GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124