Module:inline: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 3: | Line 3: | ||
function export.parse(term) | function export.parse(term) | ||
local args = {} | local args = {} | ||
local i, key, value = | local i, key, value = 1 | ||
while i < #term do | while i < #term do | ||
key, value, i = mw.ustring.match(term, "<([a-zA-Z]+):([^>]+)>()" | key, value, i = mw.ustring.match(term, "<([a-zA-Z]+):([^>]+)>()", i) | ||
if key and value then args[key] = value else break end | |||
if key and value then args[key] = value end | |||
end | end | ||
return mw.ustring.gsub(term, "<[a-zA-Z]+:[^>]+>", ""), args | return mw.ustring.gsub(term, "<[a-zA-Z]+:[^>]+>", ""), args |
Revision as of 22:36, 20 February 2024
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)
local args = {}
local i, key, value = 1
while i < #term do
key, value, i = mw.ustring.match(term, "<([a-zA-Z]+):([^>]+)>()", i)
if key and value then args[key] = value else break end
end
return mw.ustring.gsub(term, "<[a-zA-Z]+:[^>]+>", ""), args
end
return export