-- Add intrinsic dimensions to images that do not already specify them. -- This reserves their layout space before the browser has loaded the file. function Image(image) if image.attributes.width or image.attributes.height then return image end local ok, mime_type, contents = pcall(pandoc.mediabag.fetch, image.src) if not ok or not contents then return image end local sized, dimensions = pcall(pandoc.image.size, contents) if not sized then return image end image.attributes.width = tostring(math.floor(dimensions.width + 0.5)) image.attributes.height = tostring(math.floor(dimensions.height + 0.5)) return image end