1 Star 0 Fork 0

风不会停息/pandoc-plug

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
filter-picture.lua 1.73 KB
一键复制 编辑 原始数据 按行查看 历史
风不会停息 提交于 2025-08-19 14:25 +08:00 . add
-- filter-picture.lua ?????
local function convertImageToBase64(imagePath)
print("convertImageToBase64 =>: " .. imagePath)
local handle = io.popen('base64 -w 0 ' .. imagePath) -- ????????? base64 ???????? base64
local base64Image = handle:read('*a')
handle:close()
return base64Image
end
local function getFileExtension(filename)
return string.match(filename, "%.([^%.]+)$")
end
local function urlDecode(s)
s = string.gsub(s, '%%(%x%x)', function(h)
return string.char(tonumber(h, 16))
end)
return s
end
-- ???????????????????????base64
function Image(elem)
print("----")
print(elem.src)
local alt_text = elem.caption
local base_path = string.match(elem.src, "^(.-)%.md$")
local imagePath = elem.src:gsub('^../..', '')
if base_path then
print("base_path:".. base_path)
local new_src = base_path .. ".svg"
print("new_src:".. new_src)
imagePath = new_src:gsub('^../..', '')
print("imagePath:".. imagePath)
end
print(imagePath)
print("D:/document/hong" .. imagePath)
local path = "D:/document/hong" .. imagePath
print("add longpath: == " .. urlDecode(path))
local base64Image = convertImageToBase64(urlDecode(path))
-- print("transfer image: == " .. base64Image)
-- ???????????
-- local extension = urlDecode(path):match('%.([^%.]+)$')
local extension = getFileExtension(path)
print(extension)
print("transfer image: == " .. extension)
if extension == "svg" then
elem.src = 'data:image/svg+xml;base64,' .. base64Image -- ??????????? base64 ????
else
elem.src = 'data:image/png;base64,' .. base64Image -- ??????????? base64 ????
end
return elem
end
return {
{ Image = Image }
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Lua
1
https://gitee.com/handcontent/pandoc-plug.git
git@gitee.com:handcontent/pandoc-plug.git
handcontent
pandoc-plug
pandoc-plug
master

搜索帮助