Skip to content

Commit

Permalink
Merge 433795c into 5001efe
Browse files Browse the repository at this point in the history
  • Loading branch information
Omikhleia committed May 5, 2023
2 parents 5001efe + 433795c commit 43a9440
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions packages/converters/init.lua
Expand Up @@ -59,11 +59,12 @@ function package.register (_, sourceExt, targetExt, command)
end

function package.checkConverters (_, source)
local resolvedSrc = SILE.resolveFile(source) or SU.error("Couldn't find file " .. source)
for _, converter in ipairs(SILE.scratch.converters) do
local extLen = string.len(converter.sourceExt)
if ((string.len(source) > extLen) and
(string.sub(source, -extLen) == converter.sourceExt)) then
return applyConverter(source, converter)
if ((string.len(resolvedSrc) > extLen) and
(string.sub(resolvedSrc, -extLen) == converter.sourceExt)) then
return applyConverter(resolvedSrc, converter)
end
end
return source -- No conversion needed.
Expand All @@ -75,17 +76,23 @@ function package:_init ()
SILE.scratch.converters = {}
end
extendCommand("include", function (options, content, original)
local result = self:checkConverters(options.src)
if not result then
local source = SU.required(options, "src", "include (converters)")
local result = self:checkConverters(source)
if result then
options["src"] = result
original(options, content)
else
SU.error("Conversion failure for include '" .. source ..'"')
end
end)
extendCommand("img", function (options, content, original)
local result = self:checkConverters(options.src)
if not result then
local source = SU.required(options, "src", "img (converters)")
local result = self:checkConverters(source)
if result then
options["src"] = result
original(options, content)
else
SU.error("Conversion failure for image '" .. source ..'"')
end
end)
self:deprecatedExport("register", self.register)
Expand Down

0 comments on commit 43a9440

Please sign in to comment.