Search code examples
luapandoc

Pandoc Lua Filter: How to access the title variable?


My document looks like this

---
title: 'Test'
---

lorem ipsum

I want to access the title variable to print it like this:

function Image (elem)
elem.attributes.caption = 'Image of chapter ' .. title
return elem

The caption of all images should be: 'Image of chapter Test'.


Solution

  • Something like this should work (untested), inspired by the docs:

    title = nil
    
    function Meta(m)
      title = m.title
      return m
    end
    
    function Image (elem)
      elem.attributes.caption = 'Image of chapter ' .. title
      return elem
    end