模組:Vfxd
![文档图示](http://upload.wikimedia.org/wikipedia/commons/thumb/4/43/Test_Template_Info-Icon_-_Version_%282%29.svg/50px-Test_Template_Info-Icon_-_Version_%282%29.svg.png)
您可能想要创建本Scribunto模块的文档。 编者可以在本模块的沙盒 (创建 | 镜像)和测试样例 (创建)页面进行实验。 请在/doc子页面中添加分类。本模块的子页面。 |
local vfxd = {}
local mError = require("Module:Error")
local yesno = require("Module:Yesno")
local function text(link, text, defcolor)
defcolor = defcolor or ''
if text == '' then
text = '<span style="color:' .. defcolor ..'">' .. link .. '</span>'
else
--先刪掉惱人的各個標籤上的格式(class title id)
text = (string.gsub(text, '(.-)', function(x)
-- 刪掉class
local delformat = string.gsub(x, 'class=(\'|")(.-)(\'|")', '')
-- 刪掉title
delformat = string.gsub(delformat, 'title=(\'|")(.-)(\'|")', '')
-- 刪掉id
delformat = string.gsub(delformat, 'id=(\'|")(.-)(\'|")', '')
-- 刪掉<big>/<small>,干擾
delformat = string.gsub(delformat, '<%/?big(.-)>', '')
-- 刪掉<templatestyles>,干擾,class都刪掉這也沒用了
delformat = string.gsub(delformat, '<templatestyles(.-)>', '')
-- 刪掉<mark>,干擾,不要在標題中隱藏文字
delformat = string.gsub(delformat, '<%/?mark(.-)>', '')
return delformat
end))
--生成顏色文字
-- 兼容(順便處理不必要的連結)
text = (string.gsub(text, '%[%[([^\n]-)%]%]', function(y)
local text = string.gsub(y, '^.-%|(.-)$', '%1')
return '<span style="color:' .. defcolor ..'">' .. text .. '</span>'
end))
text = (string.gsub(text, '%[(.*)%]', function(text)
return '<span style="color:' .. defcolor ..'">' .. text .. '</span>'
end))
end
return text
end
function vfxd.redlink(frame)
local link = frame.args[1] or ''
local text = frame.args[2] or ''
if link == '' then
return mError.error({[1]="錯誤:<code>-{[[模块:Vfxd]]}-</code>函數<code>redlink</code>之參數<code>1</code>不得為空"})
else
if text == '' then
text = '<span style="color:#ba0000">' .. link .. '</span>'
else
--先刪掉惱人的各個標籤上的格式(class title id)
text = (string.gsub(text, '(.-)', function(x)
-- 刪掉class
local delformat = string.gsub(x, 'class=(\'|")(.-)(\'|")', '')
-- 刪掉title
delformat = string.gsub(delformat, 'title=(\'|")(.-)(\'|")', '')
-- 刪掉id
delformat = string.gsub(delformat, 'id=(\'|")(.-)(\'|")', '')
-- 刪掉<big>,干擾
delformat = string.gsub(delformat, '<%/?big(.-)>', '')
-- 刪掉<templatestyles>,干擾,class都刪掉這也沒用了
delformat = string.gsub(delformat, '<templatestyles(.-)>', '')
-- 刪掉<mark>,干擾,不要在標題中隱藏文字
delformat = string.gsub(delformat, '<%/?mark(.-)>', '')
return delformat
end))
--處理紅鏈
text = (string.gsub(text, '%[%[([^\n]-)%]%]', function(y)
local text = string.gsub(y, '^.-%|(.-)$', '%1')
return '<span style="color:#ba0000">' .. text .. '</span>'
end))
end
return "[[" .. link .. "|" .. text .."]]"
end
end
function vfxd.vfxdlink(frame)
local args = frame:getParent().args
local isredlink = yesno(args['redlink'])
local defcolor = args['color']
local ret = {}
local i = 1
local title = ''
local text = ''
local link = ''
while true do
title = args[i] or ''
text = args['text' .. i] or ''
if title ~= '' then
if isredlink then
ret[#ret + 1] = '<span id="' .. title .. '">[[:' .. title .. '|' .. text(link, text, (defcolor or '#ba0000')) .. ']]</span>'
elseif text == '' then
ret[#ret + 1] = '<span id="' .. title .. '">[[:' .. title .. ']]</span>'
else
ret[#ret + 1] = '<span id="' .. title .. '">[[:' .. title .. '|' .. text(link, text, (defcolor or '#36b')) .. ']]</span>'
end
else
break
end
end
ret = mw.text.listToText(ret, '、', '、')
return ret
end
return vfxd