Editing Module:D'ni Tools
From Guild of Archivists
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 10: | Line 10: | ||
local args = {} | local args = {} | ||
local origArgs | local origArgs | ||
local output = '' | local output = '' | ||
Line 17: | Line 16: | ||
local function num2dnum(str,sep) | local function num2dnum(str,sep) | ||
str = mw.text.trim(str) | str = mw.text.trim(str) | ||
Line 72: | Line 70: | ||
end | end | ||
local function dnum2dnifont(str | local function dnum2dnifont(str) | ||
local output = mw.text.trim(str) | local output = mw.text.trim(str) | ||
output = mw.ustring.gsub(output,"%d%d", {["24"] = "}", | |||
["23"] = "{", | ["23"] = "{", | ||
["22"] = "\\", | ["22"] = "\\", | ||
Line 101: | Line 91: | ||
}) | }) | ||
output = mw.ustring.gsub(output,"%|","") | |||
return output | return output | ||
Line 190: | Line 177: | ||
local function parseDniWord(input | local function parseDniWord(input) | ||
local output | local output | ||
local word = mw.text.trim(input) | local word = mw.text.trim(input) | ||
Line 206: | Line 191: | ||
suffix = prefix | suffix = prefix | ||
end | end | ||
if (word == '') then | if (word == '') then | ||
Line 216: | Line 200: | ||
elseif (first == '-') then | elseif (first == '-') then | ||
output = prefix..'[[Dictionary:'..word..'|'..mw.ustring.sub(word,2,-1)..']]'..suffix | output = prefix..'[[Dictionary:'..word..'|'..mw.ustring.sub(word,2,-1)..']]'..suffix | ||
elseif (last == '-') then | elseif (last == '-') then | ||
output = prefix..'[[Dictionary:'..word..'|'..mw.ustring.sub(word,1,-2)..']]'..suffix | output = prefix..'[[Dictionary:'..word..'|'..mw.ustring.sub(word,1,-2)..']]'..suffix | ||
elseif (first == '.' or first == '!' or first == '?' or first == ',') then | elseif (first == '.' or first == '!' or first == '?' or first == ',') then | ||
output = first..prefix..'[[Dictionary:'..mw.ustring.sub(word,2,-1)..'|'..mw.ustring.sub(word,2,-1)..']]'..suffix | output = first..prefix..'[[Dictionary:'..mw.ustring.sub(word,2,-1)..'|'..mw.ustring.sub(word,2,-1)..']]'..suffix | ||
elseif (last == ',') then | elseif (last == ',') then | ||
output = prefix..'[[Dictionary:'..mw.ustring.sub(word,1,-2)..'|'..mw.ustring.sub(word,1,-2)..']]'..suffix..last | output = prefix..'[[Dictionary:'..mw.ustring.sub(word,1,-2)..'|'..mw.ustring.sub(word,1,-2)..']]'..suffix..last | ||
else | else | ||
output = prefix..'[[Dictionary:'..word..'|'..word..']]'..suffix | output = prefix..'[[Dictionary:'..word..'|'..word..']]'..suffix | ||
end | end | ||
Line 250: | Line 229: | ||
else | else | ||
origArgs = frame.args | origArgs = frame.args | ||
end | end | ||
for word in ipairs(origArgs) do | for word in ipairs(origArgs) do | ||
output = output..parseDniWord(origArgs[word] | output = output..parseDniWord(origArgs[word]) | ||
end | end | ||
return output | return output | ||
end | end | ||
Line 306: | Line 250: | ||
function p.num2dnum(frame) | function p.num2dnum(frame) | ||
local output | |||
local val = frame.args["val"] or frame.args[1] | |||
if (args[ | if (frame.args["format"] == 'dnifont') then | ||
output = dnum2dnifont(num2dnum(val)) | output = dnum2dnifont(num2dnum(val)) | ||
else | else | ||
output = num2dnum(val,args[ | output = num2dnum(val,frame.args["sep"]) | ||
end | end | ||
Line 336: | Line 266: | ||
function p.dnifont2dnum(frame) | function p.dnifont2dnum(frame) | ||
return dnifont2dnum(frame.args[1],frame.args["sep"]) | |||
return dnifont2dnum(args[1],args[ | |||
end | end | ||
function p.dnum2num(frame) | function p.dnum2num(frame) | ||
return dnum2num(frame.args[1],frame.args["sep"]) | |||
return dnum2num(args[1],args[ | |||
end | end | ||
return p | return p |