Module:Links:修订间差异
无编辑摘要 |
无编辑摘要 |
||
第42行: | 第42行: | ||
function p.links(frame) --实现复杂连接表 | function p.links(frame) --实现复杂连接表 | ||
local args = getArgs(frame) | local args = getArgs(frame) | ||
local count = 0 | |||
for _, v in ipairs(frame) do | |||
count = count + 1 | |||
end | |||
local outstr = "" | local outstr = "" | ||
for k,v in ipairs(args)do | for k,v in ipairs(args)do | ||
第60行: | 第66行: | ||
end | end | ||
if flag==0 then | if flag==0 then | ||
outstr = outstr.."[["..tag.."]]"..","..tostring(k)..","..tostring( | outstr = outstr.."[["..tag.."]]"..","..tostring(k)..","..tostring(count).."," | ||
else | else | ||
outstr = outstr.."[["..tag.."|"..itag.."]]" | outstr = outstr.."[["..tag.."|"..itag.."]]" | ||
end | end | ||
if k < | if k < count then | ||
outstr = outstr.." • " | outstr = outstr.." • " | ||
end | end |
2024年9月17日 (二) 00:01的版本
此模块的文档可以在Module:Links/doc创建
local p = {}
local getArgs = require('Module:Arguments').getArgs
function p.str2codelist(strin) --转换字符串到unicode码位构成的数组,仅支持第一平面字符
local listout={}
local strk=1
local listk=1
while strk <= #strin do
if(math.modf(string.byte(strin,strk)/16)==14)then
listout[listk]=(string.byte(strin,strk)-224)*4096+(string.byte(strin,strk+1)-128)*64+(string.byte(strin,strk+2)-128)
listk=listk+1
strk=strk+3
elseif(math.modf(string.byte(strin,strk)/32)==6)then
listout[listk]=(string.byte(strin,strk)-192)*64+(string.byte(strin,strk+1)-128)
listk=listk+1
strk=strk+2
else
listout[listk]=string.byte(strin,strk)
listk=listk+1
strk=strk+1
end
end
return listout
end
function p.codelist2str(unicodeCodes)
local utf8Str = ""
if #unicodeCodes>0 then
for _, code in ipairs(unicodeCodes) do
if code <= 0x7F then
utf8Str = utf8Str .. string.char(code)
elseif code <= 0x7FF then
utf8Str = utf8Str .. string.char(0xC0 + math.floor(code / 64), 0x80 + (code % 64))
else
utf8Str = utf8Str .. string.char(0xE0 + math.floor(code / 4096), 0x80 + math.floor((code % 4096) / 64), 0x80 + (code % 64))
end
end
end
return utf8Str
end
function p.links(frame) --实现复杂连接表
local args = getArgs(frame)
local count = 0
for _, v in ipairs(frame) do
count = count + 1
end
local outstr = ""
for k,v in ipairs(args)do
strli = p.str2codelist(v)
local flag=0
local tag=""
local itag=""
for k2,v2 in ipairs(strli)do
if v2==p.str2codelist("#")[1] then
flag=1
else
if flag==0 then
tag=tag..p.codelist2str({v2})
else
itag=itag..p.codelist2str({v2})
end
end
end
if flag==0 then
outstr = outstr.."[["..tag.."]]"..","..tostring(k)..","..tostring(count)..","
else
outstr = outstr.."[["..tag.."|"..itag.."]]"
end
if k < count then
outstr = outstr.." • "
end
end
return frame:preprocess(outstr) --预处理
end
return p