模組:沙盒/逆襲的天邪鬼/vandalism
外觀
< 模組:沙盒
可在模組:沙盒/逆襲的天邪鬼/vandalism/doc建立此模組的說明文件
local func = {}
local function islinkeatable(text)
local test = string.lower(text)
return not (string.find(test, 'category:') == 1 or string.find(test, '分类:') == 1 or
string.find(test, '分類:') == 1 or string.find(test, 'file:') == 1 or
string.find(test, '文件:') == 1 or string.find(test, '檔案:') == 1 or
string.find(test, 'en:') == 1 or string.find(test, 'ja:') == 1 or string.find(test, 'zh:') == 1)
end
function func.eatlinks(frame)
local text = frame.args[1] or ''
text = (string.gsub(text, '%[%[([^\n]-)%]%]', function(x)
if islinkeatable(x) then
local target = string.gsub(x, '^(.-)%|.-$', '%1')
local text = string.gsub(x, '^.-%|(.-)$', '%1')
if string.find(target, ':') == 1 then
if text == target then
text = string.sub(text, 2)
end
return '<span style="color:#36b;cursor:pointer;">' .. text .. '</span>'
else
if mw.title.new(target):getContent() then
return '<span style="color:#0645ad;cursor:pointer;">' .. text .. '</span>'
else
return '<span style="color:#ba0000;cursor:pointer;">' .. text .. '</span>'
end
end
else
return '[[' .. x .. ']]'
end
end))
text = (string.gsub(text, '%[https?://[^\n]- ([^\n]-)%]', function(x)
return '<span style="color:#36b;cursor:pointer;">' .. x .. '</span>'
end))
return text
end
return func