ah, yes, good, that way we're sure we iterate on a fixed list, a snapshot before the changes.
so with this, and a check on the mime type, we get something like :
-----
local outputfile = PANDOC_STATE.output_file:gsub("%.md", "")
local function prefixName(s)
return s:gsub("([^/]*)$", outputfile .. "_%1")
end
function Image(img)
img.src = prefixName(img.src)
return img
end
function Pandoc(doc)
for _,f in ipairs(pandoc.mediabag.list()) do
local fp = f.path
local mt, contents = pandoc.mediabag.lookup(fp)
if mt:match("^[^/]*") == "image" then
local fpnew = prefixName(fp)
pandoc.mediabag.insert(fpnew, mt, contents)
pandoc.mediabag.delete(fp)
end
end
end
-----