Module:User:Wyang/zh-cat

local export = {} local sub = mw.ustring.sub local gsub = mw.ustring.gsub local match = mw.ustring.match

function export.cat(frame) local text = frame.args[1] local pagetitle = mw.title.getCurrentTitle.text local content = mw.title.new(pagetitle):getContent if content then while match(content, "%{%{zh%-cat%|[^%}]+%}%}\n%{%{zh%-cat%|[^%}]+%}%}") do			original = match(content, "%{%{zh%-cat%|[^%}]+%}%}\n%{%{zh%-cat%|[^%}]+%}%}") cats = sub(gsub(original, "%}%}\n%{%{zh%-cat", ""), 10, -3) local empty, target = {}, {} for cat in mw.text.gsplit(cats, "|") do				if not empty[cat] then empty[cat] = true table.insert(target, cat) end end content = gsub(content, "%{%{zh%-cat%|[^%}]+%}%}\n%{%{zh%-cat%|[^%}]+%}%}", "") end end return content end

return export