Module:User:Wyang/der

This is a private module sandbox of Wyang, for their own experimentation. Items in this module may be added and removed at Wyang's discretion; do not rely on this module's stability.


local export = {}

function export.make(frame)
	local args = frame:getParent().args
	text = args[1]
	text = mw.ustring.gsub(text, "ス", "{")
	text = mw.ustring.gsub(text, "ぞ", "|")
	text = mw.ustring.gsub(text, "ど", "}")
	text = mw.ustring.gsub(text, "も", "\n")
	text = mw.ustring.gsub(text, "さ", "=")
	if mw.ustring.match(text, "%{%{zh%-l|[^}]+%{") then
		return text
	end
	text = mw.ustring.gsub(text, "|tr=", "|")
	text = mw.ustring.gsub(text, "|gloss=", "|")
	
	for line in mw.text.gsplit(text, "\n") do
		if not mw.ustring.match(line, "^%* ?%{%{zh%-l.+%}%}$") then
			return text
		end
	end
	
	local result = {}
	for line in mw.text.gsplit(text, "\n") do
		table.insert(result, (mw.ustring.gsub(mw.ustring.gsub(mw.ustring.gsub(line, "%}%}", ""), "^%* ?%{%{zh%-l%|", ""), "|", ":")))
	end
	
	return "{{zh-der|" .. table.concat(result, "|") .. "}}"
end

return export