convert Lua's table to markdown metablock #10041
Replies: 1 comment 1 reply
-
More information is needed in order to answer the question. Please post an example of what your Lua table looks like and the desired output, presumably what you want the metadata corresponding to your Lua table to look like in Markdown. It would also be helpful if you can post some code showing what you are trying to do. Generally speaking metadata leaf values can be plain strings so in the simplest case you can just stick a table where all leaf values are strings into the metadata tree. You will probably need to do everything inside a For example here is a script which collects the urls of all links in a document and builds a table where the keys are the stringified link texts and the values are the urls, then puts that table into the metadata: -- Declare the table variable outside and before the functions.
local urls = { }
local collect_url = function(link)
local url = link.target
if "" == url then -- link has no url
return nil
end
local key = pandoc.utils.stringify(link)
urls[key] = url
return nil -- don't change the link
end
local add_metadata = function(meta)
meta.urls = urls
-- Must return meta for the change to take effect!
return meta
end
-- Run them separately one after the other
return {
{
Link = collect_url
},
{
Meta = add_metadata
}
} Now suppose you have this input: [Dewey](https://example.org/dewey.html),
[Huey](https://example.org/huey.html)
and [Louie](https://example.org/louie.html). Run the filter pandoc -L collect-urls.lua --standalone -w markdown input.md and get this output ---
urls:
Dewey: "https://example.org/dewey.html"
Huey: "https://example.org/huey.html"
Louie: "https://example.org/louie.html"
---
[Dewey](https://example.org/dewey.html),
[Huey](https://example.org/huey.html) and
[Louie](https://example.org/louie.html). A silly example but you get the idea! |
Beta Was this translation helpful? Give feedback.
-
How to convert lua's table to markdown metablock in lua filter?
Beta Was this translation helpful? Give feedback.
All reactions