|
|
| (One intermediate revision by the same user not shown) |
| Line 1: |
Line 1: |
| local m_put = require("Module:parse utilities")
| |
| local m_table = require("Module:table")
| |
|
| |
|
| local gsub = mw.ustring.gsub
| |
| local PAGENAME = gsub(mw.title.getCurrentTitle().text, "%s", " ")
| |
| local NAMESPACE = mw.title.getCurrentTitle().nsText
| |
| local match = mw.ustring.match
| |
| local gmatch = mw.ustring.gmatch
| |
|
| |
| local export = {}
| |
|
| |
| local function ncategories(categories)
| |
| local out_categories = {}
| |
| for key, cat in ipairs(categories) do
| |
| out_categories[key] = "[[Category:" .. cat .. "]]"
| |
| end
| |
|
| |
| return NAMESPACE == "Template" and "" or table.concat(out_categories, "")
| |
| end
| |
|
| |
| local function link(term,alt)
| |
| return "[[Contionary:*" .. term .. "|*" .. (alt or term) .. "]]"
| |
| end
| |
|
| |
| function export.getLink(frame)
| |
| local a = 2
| |
| local params = {
| |
| [1] = {},
| |
| [a] = {list = true}, -- Nentammmi
| |
| }
| |
|
| |
| local args = require("Module:parameters").process(frame:getParent().args, params)
| |
|
| |
| local code = frame.args[1]
| |
| local lang = require("Module:languages").getByCode(code)
| |
|
| |
| local links = {}; local categories = {}; local alts = {};
| |
| -- WIP
| |
| for i, item in ipairs(args[a]) do
| |
| if item == "+" then
| |
| table.insert(links," ")
| |
| elseif item == "-" then
| |
| table.insert(links, item)
| |
| elseif item:find("<") and not item:find("^[^<]*<[a-z]*[^a-z:]") then
| |
| local run = m_put.parse_balanced_segment_run(item, "<", ">")
| |
| local orig_param = a + i - 1
| |
| local function parse_err(msg)
| |
| error(msg .. ": " .. orig_param .. "= " .. table.concat(run))
| |
| end
| |
| local term = run[1]:gsub("%*","")
| |
|
| |
| for j = 2, #run - 1, 2 do
| |
| local modtext = run[j]:match("^<(.*)>$")
| |
| local prefix, arg = modtext:match("^([a-z]+):(.*)$")
| |
|
| |
| if item:match("><") then
| |
| if prefix == "a" then
| |
| table.insert(links, link(term, arg))
| |
| table.insert(alts, arg)
| |
| elseif prefix == "c" then
| |
| table.insert(categories, lang:getCanonicalName() .. " terms from Nentammmi " .. arg)
| |
| table.insert(alts, term)
| |
| end
| |
| elseif prefix == "a" then
| |
| table.insert(links, link(term, arg))
| |
| table.insert(categories, lang:getCanonicalName() .. " terms from Nentammmi " .. term)
| |
| table.insert(alts, arg)
| |
| elseif prefix == "c" then
| |
| table.insert(links, link(term))
| |
| table.insert(categories, lang:getCanonicalName() .. " terms from Nentammmi " .. arg)
| |
| table.insert(alts, term)
| |
| end
| |
| end
| |
| else
| |
| table.insert(links, link(args[a][i]))
| |
| table.insert(categories, lang:getCanonicalName() .. " terms from Nentammmi " .. args[a][i])
| |
| table.insert(alts, args[a][i])
| |
| end
| |
|
| |
| if i~=1 and links[i-1] == "-" then links[i] = links[i]:gsub("%|%*","|") end
| |
| if i~=1 and links[i-1] ~= " " then links[i] = links[i]:gsub("%|%*%-","|-") end
| |
| if i~=1 and alts[i-1]:match("%-$") then links[i] = links[i]:gsub("%|%*","|") end
| |
| end
| |
|
| |
| return table.concat(links) .. ncategories(categories)
| |
| end
| |
|
| |
|
| |
| return export
| |