More actions
remove this debugging stuff |
No edit summary |
||
| Line 9: | Line 9: | ||
["TDS"] = "The Dark Secret", | ["TDS"] = "The Dark Secret", | ||
["TBN"] = "The Brightest Night", | ["TBN"] = "The Brightest Night", | ||
-- TODO: add the rest of the books | |||
} | } | ||
Revision as of 20:30, 18 April 2025
Documentation for this module may be created at Module:Book appearances/doc
-- local string = require("Module:String")
local p = {}
local abbrs = {
["TDP"] = "The Dragonet Prophecy",
["TLH"] = "The Lost Heir",
["THK"] = "The Hidden Kingdom",
["TDS"] = "The Dark Secret",
["TBN"] = "The Brightest Night",
-- TODO: add the rest of the books
}
-- str: String to parse
-- delim: String to use to join the book names (default '\n')
function p._appearancesList(str, fmt, delim)
if not str or str == "" then
return '{{error|Please specify the <code>str</code> or first unnamed param.}}'
end
fmt = fmt or '%s'
delim = delim or '\n'
local names = mw.text.split(str, ' ', true)
-- iterate over substrings
for i, v in ipairs(names) do
local full = abbrs[v]
if full then
names[i] = string.format(fmt, full)
else
return '{{error|Unrecognized abbreviation <code>' .. v .. '</code>}}'
end
end
return table.concat(names, delim)
end
-- wrapper for _appearancesList, untested
function p.appearancesList(frame)
local args = frame.args
local str = args.str or args[1]
local fmt = args.fmt or args[2] or "''[[%s]]''"
local delim = args.delim or args[3] or '<br>'
return frame:preprocess(p._appearancesList(str, fmt, delim))
end
return p