模組:沙盒/逆襲的天邪鬼/userpage

文出維基大典

可在模組:沙盒/逆襲的天邪鬼/userpage/doc建立此模組的說明文件

local z = {}

function z.nowiki(frame)
    local text = frame.args[1] or ''
    return mw.text.nowiki(text)	
end

string.split = function(s, p)
    local rt = {}
    string.gsub(s, '[^'..p..']+', function(w)
    	table.insert(rt, w)
    end)
    return rt
end

function z.list2vtext(frame)
    local lists = {
        '=== *(.-) *=== *',
        '== *(.-) *== *',
        '%* *(.*)',
        '( +)'
    }
    local replaces = {
        'VH3',
        'VH2',
        'Vtext',
        'Vtext'
    }

    local text = frame.args[1] or ''
    local output = {}
    for _, w in ipairs(string.split(text..'\n', '\n')) do
    	for i, p in ipairs(lists) do
            local m = string.match(w, p)
            if m then
                table.insert(output, frame:expandTemplate{ title = replaces[i], args = { m } })
                break
            end
        end
    end
    return table.concat(output)
end

return z