Module:Sandbox/Aseleste/Indexer: Difference between revisions

Content deleted Content added
test: debug
improve: code, remove: debug code
Line 61:
local result = {}
for arg_k, arg_v in pairs(args) do
local arg_k_trim = mw.text.arg_k:trim(arg_k)
if mw.ustring.arg_k_trim:match(arg_k_trim, "^table_") then
local key = mw.ustring.arg_k_trim:gsub(arg_k_trim, "table_", "", 1)
result[key] = as_key_content_function(mw.text.arg_v:trim(arg_v))
end
end
Line 79:
local content = ""
for line_number, line in ipairs(mw.text.:split(text, "\n", true)) do -- is \n sufficient
if mw.ustring.line:match(line, "^__M_INDEX__") then
-- finish result
for index, category in ipairs(context) do
Line 94:
-- change context
context = {}
for category in mw.ustring.line:gmatch(line, "%[([^%]]*)%]") do
table.insert(context, category)
end
Line 125:
as_key_content_function = function(text)
local function func(content)
local e =return text:gsub("__M_CONTENT__", escape_replacement(content))
error(text .. e)
return e
end
return func
Line 136 ⟶ 134:
as_value_content_function = function(text)
local function func(category)
return mw.ustring.text:gsub(text, "__M_CATEGORY__", escape_replacement(category))
end
return func
Line 146 ⟶ 144:
local function func(left, right)
-- some improvements could be made here
return mw.ustring.text:gsub(mw.ustring.gsub(text, "__M_LEFT__", escape_replacement(left)), :gsub("__M_RIGHT__", escape_replacement(right))
end
return func
Line 153 ⟶ 151:
-- escapes replacement, replace '%' with '%%'
escape_replacement = function(text)
return mw.ustring.text:gsub(text, "%%", "%%%%")
end