Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Processing lists in lua filters [question] #2

Open
retostauffer opened this issue Aug 17, 2022 · 5 comments
Open

Processing lists in lua filters [question] #2

retostauffer opened this issue Aug 17, 2022 · 5 comments

Comments

@retostauffer
Copy link

Goal: I am currently working on a shortcode for bootstrap carousel. To allow to define images, alt, and captions I try to configure it via .yml list.

My test index.qmd looks as follows:

---
title: "My Website"
carousel:
    - image: _images/unsplash-1.jpg
      alt: foooo
    - image: _images/unsplash-2.jpg
      alt: foooo
reto: "Just a test string"
---

My lua script (carousel.lua; shortcode extension) in a minimalized version looks as follows:

carousel = function(args, kwargs, meta)
    -- extracting Str from meta
    print(pandoc.utils.stringify(meta["reto"]))
    -- extracting List from meta
    print(pandoc.utils.stringify(meta["carousel"]))
    -- dummy return
    return pandoc.RawInline("html", "test")
end

return { ["carousel"] = carousel }

The problem: Processing meta["reto"] works as expected, however, meta["carousel"] (List) gives a WARNING: Unsupported type 'List' for key carousel.

Question: Is it somehow possible to process lists or a better way to access the meta needed, or is this just not possible with quarto/lua?

Any hint would be warmly welcome. Thanks in advance!

@dragonstyle
Copy link

One suggestion- have you returned a pandoc.List

https://pandoc.org/lua-filters.html#module-pandoc.list

Let us know if that works if not I can take a closer look!

@retostauffer
Copy link
Author

Hy @dragonstyle

thanks for your quick reply! I've tried to call pandoc.List(meta.carousel) already with the same result. The warning is thrown as soon as meta.carousel (the list) is accessed. Rendering still works, but no access to the meta info.

I have put together a minimal quarto website project which contains the code (slightly modified) as shown above if that helps.

Not urgent/important at all, but would be nice to be able to do this in the future. Thanks in advance!

@dragonstyle
Copy link

Thank you this is really helpful - I can reproduce the issue and will take a look!

@nichtich
Copy link

I encountered a similar problem: quarto shortcodes cannot access full metadata hierarchy unless the hierarchy of a nested key is known, so iterating all values of carousel is not possible. My solution was to not use shortcode library but a plain Pandoc lua filter.

@retostauffer
Copy link
Author

retostauffer commented Aug 18, 2022

Thanks @nichtich, I will have a look at your filter! Thanks.
In the mean time I also wrote a filter which injects jQuery/HTML.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants