Replies: 2 comments 5 replies
|
I believe the docs are correct. Relevant code is at https://github.com/jgm/pandoc/blob/main/src/Text/Pandoc/MediaBag.hs#L97-L104 |
5 replies
|
so this is a good time for me to learn to write a lua filter. please tell me if there's any problem or better idea -- rename image file name in media to sha1 hash
-- pandoc --lua-filter image2hash.lua t.docx --extract-media=. -o t.html
Pandoc = function (doc)
local images = {}
for filepath, mimetype, contents in pandoc.mediabag.items() do
table.insert(images, {filepath, mimetype, contents})
pandoc.mediabag.delete(filepath)
end
local filepaths = {}
for item in pandoc.List(images):iter() do
local filepath, mimetype, contents = table.unpack(item)
local sha1 = pandoc.utils.sha1(contents)
local ext = select(2, pandoc.path.split_extension(filepath) ) or '.png'
filepath = 'media/' ..sha1 ..ext
filepaths[#filepaths+1] = filepath
pandoc.mediabag.insert(filepath, mimetype, contents)
end
local n = 0
return doc:walk{Image = function(el) n=n+1 el.src = filepaths[n] return el end}
end |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
hi, doc says that ir default to sha1 but I always get names like media/image1.jpg , which is not original path and not sha1
I think sha1 name is better for finding out difference in image updating. is the documentation wrong? is there any parameter to force extract media to use sha1 based file name?
All reactions