transfer from old repo

This commit is contained in:
Andreas Gammelgaard Damsbo 2026-08-19 09:27:27 +02:00
commit 277e2b8cf3
No known key found for this signature in database
1111 changed files with 83736 additions and 0 deletions

View file

@ -0,0 +1,65 @@
--[[
This file defines a few helper functions, in particular with respect to pandoc.
--]]
local Options = require("acronyms_options")
local Helpers = {}
-- Helper function to determine pandoc's version.
-- `version` must be a table of numbers, e.g., `{2, 17, 0, 1}`
function Helpers.isAtLeastVersion(version)
-- `PANDOC_VERSION` exists since 2.1, but we never know...
if PANDOC_VERSION == nil then
return false
end
-- Loop up over the components
-- e.g., `2.17.0.1` => [0]=2, [1]=17, [2]=0, [3]=1
for k, v in ipairs(version) do
if PANDOC_VERSION[k] == nil or PANDOC_VERSION[k] < version[k] then
-- Examples: 2.17 < 2.17.0.1, or 2.16 < 2.17
return false
elseif PANDOC_VERSION[k] > version[k] then
-- Example: 2.17 > 2.16.2 (we do not need to check the next!)
return true
end
end
-- At this point, all components are equal
return true
end
-- Helper function to determine whether a metadata field is a list.
function Helpers.isMetaList(field)
-- We want to know whether we have multiple values (MetaList).
-- Pandoc 2.17 introduced a compatibility-breaking change for this:
-- the `.tag` is no longer present in >= 2.17 ;
-- the `pandoc.utils.type` function is only available in >= 2.17
if Helpers.isAtLeastVersion({2, 17}) then
-- Use the new `pandoc.utils.type` function
return pandoc.utils.type(field) == "List"
else
-- Use the (old) `.tag` type attribute
return field.t == "MetaList"
end
end
-- Helper function to generate the ID (identifier) from an acronym key.
-- The ID can be used for, e.g., links.
function Helpers.key_to_id(key)
return Options["id_prefix"] .. key
end
-- Similar helper but for the link itself (based on the ID).
function Helpers.key_to_link(key)
return "#" .. Helpers.key_to_id(key)
end
return Helpers