yum-slop/yummers.dev

source code for https://yummers.dev

git clone https://git.yummers.dev/yum-slop/yummers.dev

yumadd scripts for inline ToC and image dimensioning49b768a

master
657 B21 linesraw
1-- Add intrinsic dimensions to images that do not already specify them.
2-- This reserves their layout space before the browser has loaded the file.
3function Image(image)
4  if image.attributes.width or image.attributes.height then
5    return image
6  end
7
8  local ok, mime_type, contents = pcall(pandoc.mediabag.fetch, image.src)
9  if not ok or not contents then
10    return image
11  end
12
13  local sized, dimensions = pcall(pandoc.image.size, contents)
14  if not sized then
15    return image
16  end
17
18  image.attributes.width = tostring(math.floor(dimensions.width + 0.5))
19  image.attributes.height = tostring(math.floor(dimensions.height + 0.5))
20  return image
21end