Skip to content

Lua filter to extract document metadata and include in the body #4042

Answered by cscheid
ratnanil asked this question in Q&A
Discussion options

You must be logged in to vote

Try this:

local my_key_values = {}

function Meta(meta)
  for key, value in pairs(meta.mymeta) do
    my_key_values[key] = value
  end
end

-- thank you copilot
local function by_sorted_keys(t)
  local keys = {}
  for k in pairs(t) do table.insert(keys, k) end
  table.sort(keys)
  local i = 0      -- iterator variable
  local iter = function ()   -- iterator function
    i = i + 1
    if keys[i] == nil then return nil
    else return keys[i], t[keys[i]]
    end
  end
  return iter
end

function Header(element)
  if element.level == 1 then
    local plain = pandoc.Para({})

    for key, value in by_sorted_keys(my_key_values) do
      plain.content:insert(pandoc.Strong(pandoc.Str(key .. ": …

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@pagiraud
Comment options

@cscheid
Comment options

@pagiraud
Comment options

Answer selected by ratnanil
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
lua Issues related to the lua codebase, filter chain, etc
3 participants