Editing Module:GainLoss
From Fallen London Wiki
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 398: | Line 398: | ||
return result, nil | return result, nil | ||
+ | end | ||
+ | |||
+ | local function test_escape_prop_cat(text) | ||
+ | local cats = '' | ||
+ | while mw.ustring.find(text, '%[%[Category:.-%]%]') ~= nil do | ||
+ | cats = cats .. mw.ustring.match(text, '%[%[Category:.-%]%]') | ||
+ | text = mw.ustring.gsub(text, '%[%[Category:.-%]%]', '', 1) | ||
+ | end | ||
+ | local props = '' | ||
+ | while mw.ustring.find(text, '{{#set:.-}}') ~= nil do | ||
+ | props = props .. mw.ustring.match(text, '{{#set:.-}}') | ||
+ | text = mw.ustring.gsub(text, '{{#set:.-}}', '', 1) | ||
+ | end | ||
+ | while mw.ustring.find(text, '[[|][%a ]+::[^%a ]*[%a ]+') ~= nil do | ||
+ | local prop, val = mw.ustring.match(text, '[[|]([%a ]+)::[^%a ]*([%a ]+)') | ||
+ | props = props .. '[[' .. prop .. '::' .. val .. ']]' | ||
+ | text = mw.ustring.gsub(text, '([[|])[%a ]+::([^%a ]*[%a ]+)', '%1%2', 1) | ||
+ | end | ||
+ | while mw.ustring.find(text, '|[^|]+|Property ?= ?[^|]+') ~= nil do | ||
+ | local val, prop = mw.ustring.match(text, '|([^|]+)|Property ?= ?([^|]+)') | ||
+ | props = props .. '[[' .. prop .. '::' .. val .. ']]' | ||
+ | text = mw.ustring.gsub(text, '(|[^|]+)|Property ?= ?[^|]+', '%1', 1) | ||
+ | end | ||
+ | return text .. '<br/><nowiki>' .. cats .. '</nowiki><br/><nowiki>' .. props .. '</nowiki>' | ||
end | end | ||
Line 407: | Line 431: | ||
local result, error = gainloss_message(frame, 'gain') | local result, error = gainloss_message(frame, 'gain') | ||
− | return frame:preprocess(result or error) | + | return frame:preprocess(test_escape_prop_cat(result or error)) |
end | end | ||
Line 417: | Line 441: | ||
local result, error = gainloss_message(frame, 'loss') | local result, error = gainloss_message(frame, 'loss') | ||
− | return frame:preprocess(result or error) | + | return frame:preprocess(test_escape_prop_cat(result or error)) |
+ | end | ||
+ | |||
+ | function p.compareOldVersion(frame) | ||
+ | local input = frame.args.t | ||
+ | local template = mw.ustring.match(input, '(.-)#') | ||
+ | local templateArgs = {} | ||
+ | local i = 0 | ||
+ | local unnamed = 1 | ||
+ | while mw.ustring.find(input, '#', i) ~= nil do | ||
+ | local arg = '' | ||
+ | _, i, arg = mw.ustring.find(input, '#([^#}]+)', i) | ||
+ | if mw.ustring.find(arg, '=') ~= nil then | ||
+ | local key = mw.ustring.match(arg, '(.-)=') | ||
+ | local val = mw.ustring.match(arg, '=(.*)') | ||
+ | templateArgs[key] = val | ||
+ | else | ||
+ | templateArgs[unnamed] = arg | ||
+ | unnamed = unnamed + 1 | ||
+ | end | ||
+ | end | ||
+ | local expanded = frame:expandTemplate({title=template, args = templateArgs}) | ||
+ | return frame:preprocess(test_escape_prop_cat(expanded)) | ||
end | end | ||
return p | return p |