如何禁用pandoc将图像放大到全宽



我正试图在pandoc markdown文件中包含不同大小的图片——有些大,有些小。当我通过pandoc渲染时,默认情况下,它会将所有图像拉伸/放大为全宽,使小图像变得很大且模糊。有没有办法禁用它?PDF、DOCX和HTML输出的行为是一致的。

可以通过设置widthheight属性来显式设置图像的大小:

![small image](icon.png){width=64px height=64px}
![large image](landscape.jpg){width=1024 height=768}

可以实现自动化,例如借助Lua过滤器和Image Magick的identify:

-- pass this file to pandoc via `--lua-filter=filename.lua`
function Image (img)
-- get dimensions
local width, height = nil, nil -- implement
img.attributes.width = width
img.attributes.height = height
return img
end

最新更新