Skip to content

Commit ef06cfd

Browse files
committed
don't require explicit declaration of transformers
1 parent a90dd88 commit ef06cfd

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

luaxml-sty.lua

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ function luaxml_sty.debug(...)
3232
end
3333
end
3434

35+
--- Declare new transformer
36+
---@param name string transformer name
37+
---@return table transformer object
38+
function luaxml_sty.declare_transformer(name)
39+
luaxml_sty.transformations[name] = luaxml_sty.packages.transform.new()
40+
return luaxml_sty.transformations[name]
41+
end
3542

3643

3744
--- Add luaxml-transform rule
@@ -45,7 +52,7 @@ function luaxml_sty.add_rule(current, selector, rule)
4552
-- the +v parameter type in LaTeX replaces newlines with \obeyedline. we need to replace it back to newlines
4653
rule = rule:gsub("\\obeyedline", "\n")
4754
luaxml_sty.debug("************* luaxml_sty rule: " .. selector, rule, current, (luaxml_sty.current.parameters.verbatim and "verbatim" or "not verbatim"))
48-
local transform = luaxml_sty.transformations[current]
55+
local transform = luaxml_sty.transformations[current] or luaxml_sty.declare_transformer(current)
4956
if not transform then
5057
luaxml_sty.error("Cannot find LuaXML transform object: " .. (current or ""))
5158
return nil, "Cannot find LuaXML transform object: " .. (current or "")

luaxml.sty

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ luaxml_sty.current.transformation = "#1",
3232
% declare new transformer object
3333
\NewDocumentCommand\LXMLDeclareTransformer{m}{
3434
\directlua{
35-
luaxml_sty.transformations["#1"] = luaxml_sty.packages.transform.new()
35+
% luaxml_sty.transformations["#1"] = luaxml_sty.packages.transform.new()
36+
luaxml_sty.declare_transformer("#1")
3637
}
3738
}
3839

0 commit comments

Comments
 (0)