Module:inline

Revision as of 22:10, 20 February 2024 by Maria (talk | contribs) (Created page with "local export = {} function export.parse(term, template) local args = {} local i, key, value = i while i < #term do key, value, i = mw.ustring.match(term, "<([a-zA-Z]+):([^>]+)>()") if key and value then args[key] = value end end return mw.ustring.gsub(term, "<[a-zA-Z]+:[^>]+>", ""), args end return export")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
local m_inline = require("Module:inline")
local term, args = m_inline.parse("hello<key1:value1><key2>")

Yields:

term = "hello"
args = {["key1"] = "value1", ["key2"] = true}

local export = {}

function export.parse(term, template)
    local args = {}
    local i, key, value = i
    while i < #term do
        key, value, i = mw.ustring.match(term, "<([a-zA-Z]+):([^>]+)>()")
        if key and value then args[key] = value end 
    end
    return mw.ustring.gsub(term, "<[a-zA-Z]+:[^>]+>", ""), args
end

return export