证爱网携手国内顶级家庭教育专家,如果您的家庭有夫妻不和谐、孩子沉迷游戏厌学抑郁等问题,请加微信y4882693咨询。

“Module:PatternedCandidateUtils”的版本间差异

来自证爱网见证爱
跳到导航 跳到搜索
(导入1个版本)
 
(没有差异)

2022年8月21日 (日) 10:27的最新版本

此模块的文档可以在Module:PatternedCandidateUtils/doc创建

local z = {}

function getCandidates( frame )
    local page = mw.title.new( frame.args.title ):getContent()
    local matches = {}
    local black = {}
    if frame.args.black then
        for b in mw.text.gsplit( frame.args.black, '|', true ) do
            black[b] = true
        end
    end
    for m in mw.ustring.gmatch( page, frame.args.pattern ) do
        if not black[m] and not ( frame.args.blackregex and mw.ustring.match( m, frame.args.blackregex ) ) then
            table.insert( matches, m )
        end
    end
    return matches
end

function z.count( frame )
    return #getCandidates( frame )
end

function z.list( frame )
    local list = getCandidates( frame )
    local linkprefix = frame.args.linkprefix
    for i = 1, #list do
        if linkprefix then
            list[i] = '[[:' .. linkprefix .. list[i] .. '|' .. list[i] .. ']]'
        else
            list[i] = '[[:' .. list[i] .. ']]'
        end
    end
    if #list > 0 then
        return table.concat( list, '-' )
    else
        return '暂无'
    end
end

return z