モジュール:template utilities
ナビゲーションに移動
検索に移動
このモジュールについての説明文ページを モジュール:template utilities/doc に作成できます
local export = {}
-- string manipulation functions
function export.explode(frame)
local wanted_index = tonumber(frame.args[3])
local count = 1
for item in mw.text.gsplit(frame.args[1], frame.args[2], true) do
if count == wanted_index then
return item
end
count = count + 1
end
return ""
end
function export.substr(frame)
return mw.ustring.sub(frame.args[1] or "", tonumber(frame.args[2]) or 1, tonumber(frame.args[3]) or -1)
end
function export.find(frame)
return mw.ustring.find(frame.args[1] or "", frame.args[2] or "", 1, true) or ""
end
function export.replace(frame)
return (mw.ustring.gsub(frame.args[1] or "", frame.args[2] or "", frame.args[3] or ""))
end
-- escaping functions
function export.escape_wiki(frame)
return mw.text.nowiki(frame.args[1] or "")
end
function export.escape_html(frame)
return mw.text.encode(frame.args[1] or "")
end
-- you do not want to invoke this function
function export.preprocess(frame)
return frame:preprocess(frame.args[1])
end
return export