Module:Johnuniq/dump
Documentation for this module may be created at Module:Johnuniq/dump/doc
-- Want to see exactly what is passed to a module when invoked via a template such as:
-- {{convert|1<ref>xyz</ref>|m}}
-- {{convert|1<math>xyz</math>|m}}
-- {{convert|1[[File:Help-browser.svg]]|m}}
local function dump(text, dumper)
-- Return ASCII string with dump of bytes in text.
return (text:gsub('[^0-9a-zA-Z .,]', dumper))
end
local function main_dump(frame)
local function hex_dumper(s)
return string.format('«%02x»', string.byte(s))
end
local function decimal_dumper(s)
return string.format('«%d»', string.byte(s))
end
local args = frame:getParent().args
local spec = {
{ 1 , nil , hex_dumper },
{ 'hex' , nil , hex_dumper },
{ 'decimal', nil , decimal_dumper },
{ 'nowiki' , mw.text.nowiki, hex_dumper },
}
local text
for _, t in ipairs(spec) do
text = args[t[1]]
if text then
if t[2] then
text = t[2](text)
end
return dump(text, t[3])
end
end
return '(empty)'
end
return { dump = main_dump }