Search code examples
yamlpandocreveal.js

Show a YAML metadata value in reveal.js slide (w. pandoc)


I would like to know if it's possible to print the value of a YAML metadata item in a reveal.js slide produced through pandoc.

I know these are mostly planned to use in templates and I have been able to do so without problems, but I would like to show the value of one of those in the content of a slide. Is this somehow possible?

I've looked at the template syntax ($variable-name$) but of course that does not work in the content.

Thanks!


Solution

  • One solution would be to write a short Lua filter for this:

    function Pandoc (doc)
      local meta = doc.meta
      return doc:walk {
        RawInline = function (raw)
          if raw.format == 'metavar' then
            return pandoc.utils.type(meta[raw.text]) == 'Blocks' and
              pandoc.utils.blocks_to_inlines(meta[raw.text]) or
              meta[raw.text]
          end
        end
      }
    end
    

    Usage: save the above to a file metavar.lua and use it in your conversion with --lua-filter=metavar.lua. Then include variables like this:

    The value of `title` is `title`{=metavar}.
    

    An alternative solution would be to use Quarto, which builds on pandoc and uses it under the hood. Quarto comes with short-codes that allow to access meta values:

    The value of `title` is {{< meta title >}}.