LLWiki正在建设中,欢迎加入我们!
“模块:Photrans”的版本间差异
跳转到导航
跳转到搜索
(创建页面,内容为“local p = {} local getArgs = require('module:arguments').getArgs function main(args) local rb = args[1] local rt = args[2] local newrb = '' local newrt = '' if…”) |
|||
第4行: | 第4行: | ||
local rb = args[1] |
local rb = args[1] |
||
local rt = args[2] |
local rt = args[2] |
||
local rt2 = args[3] |
|||
local newrb = '' |
local newrb = '' |
||
local newrt = '' |
local newrt = '' |
||
第9行: | 第10行: | ||
local lrb = mw.ustring.len(rb) |
local lrb = mw.ustring.len(rb) |
||
local lrt = mw.ustring.len(rt) |
local lrt = mw.ustring.len(rt) |
||
local diff = lrt * 0. |
local diff = lrt * 0.8 - lrb |
||
local space = '' |
local space = '' |
||
local important = rt2 and '!important' or '' |
|||
if diff > 0 then |
if diff > 0 then |
||
space = tostring(math.floor(diff / (lrb + 1) * 1000) / 1000)..'em' |
space = tostring(math.floor(diff / (lrb + 1) * 1000) / 1000)..'em' |
||
newrb = '<span style="margin-left:'..space..';letter-spacing:'..space..'">'..rb..'</span>' |
newrb = '<span style="margin-left:'..space..important..';letter-spacing:'..space..important..'">'..rb..'</span>' |
||
newrt = rt |
newrt = rt |
||
else |
else |
||
space = tostring(math.floor(-diff / (lrt + 1) / 0. |
space = tostring(math.floor(-diff / (lrt + 1) / 0.8 * 1000) / 1000)..'em' |
||
newrb = rb |
newrb = rb |
||
newrt = '<span style="margin-left:'..space..';letter-spacing:'..space..'">'..rt..'</span>' |
newrt = '<span style="margin-left:'..space..';letter-spacing:'..space..'">'..rt..'</span>' |
||
第24行: | 第26行: | ||
newrt = '<span class="photrans-s">'..rb..'</span>' |
newrt = '<span class="photrans-s">'..rb..'</span>' |
||
end |
end |
||
return newrb, newrt |
return newrb, newrt, rt2 |
||
end |
end |
||
function |
function one(args) |
||
⚫ | |||
local rb = args[1] or '' |
local rb = args[1] or '' |
||
local rt = args[2] or ' ' |
local rt = args[2] or ' ' |
||
第33行: | 第34行: | ||
(args.on and rt or '<span>'..rt..'</span>')..'</rt></ruby>' |
(args.on and rt or '<span>'..rt..'</span>')..'</rt></ruby>' |
||
end |
end |
||
function |
function multi(args) |
||
local fullrb = '' |
local fullrb = '' |
||
local fullrt = '' |
local fullrt = '' |
||
local flag = false |
|||
⚫ | |||
local fullrt2 = '<span class="photrans-off">' |
|||
⚫ | |||
local args = mw.text.split(v, '_') |
local args = mw.text.split(v, '_') |
||
local newrb, newrt = main(args) |
local newrb, newrt, rt2 = main(args) |
||
fullrb = fullrb..newrb |
fullrb = fullrb..newrb |
||
fullrt = fullrt..newrt |
fullrt = fullrt..newrt |
||
flag = flag or rt2 |
|||
fullrt2 = fullrt2..(rt2 and newrt or '<span class="photrans-s">'..args[1]..'</span>') |
|||
end |
|||
fullrt2 = fullrt2..'</span>' |
|||
⚫ | |||
end |
|||
function p.main(frame) |
|||
⚫ | |||
if args[2] then |
|||
return multi(args) |
|||
else |
|||
return one(args) |
|||
end |
end |
||
⚫ | |||
end |
end |
||
return p |
return p |
2022年1月14日 (五) 02:13的版本
可在模块:Photrans/doc创建此模块的帮助文档
local p = {} local getArgs = require('module:arguments').getArgs function main(args) local rb = args[1] local rt = args[2] local rt2 = args[3] local newrb = '' local newrt = '' if rt then local lrb = mw.ustring.len(rb) local lrt = mw.ustring.len(rt) local diff = lrt * 0.8 - lrb local space = '' local important = rt2 and '!important' or '' if diff > 0 then space = tostring(math.floor(diff / (lrb + 1) * 1000) / 1000)..'em' newrb = '<span style="margin-left:'..space..important..';letter-spacing:'..space..important..'">'..rb..'</span>' newrt = rt else space = tostring(math.floor(-diff / (lrt + 1) / 0.8 * 1000) / 1000)..'em' newrb = rb newrt = '<span style="margin-left:'..space..';letter-spacing:'..space..'">'..rt..'</span>' end else newrb = rb newrt = '<span class="photrans-s">'..rb..'</span>' end return newrb, newrt, rt2 end function one(args) local rb = args[1] or '' local rt = args[2] or ' ' return '<ruby><rb>'..rb..'</rb><rt'..(args[2] and '>' or ' class="photrans-s">').. (args.on and rt or '<span>'..rt..'</span>')..'</rt></ruby>' end function multi(args) local fullrb = '' local fullrt = '' local flag = false local fullrt2 = '<span class="photrans-off">' for k, v in ipairs(args) do local args = mw.text.split(v, '_') local newrb, newrt, rt2 = main(args) fullrb = fullrb..newrb fullrt = fullrt..newrt flag = flag or rt2 fullrt2 = fullrt2..(rt2 and newrt or '<span class="photrans-s">'..args[1]..'</span>') end fullrt2 = fullrt2..'</span>' return '<ruby><rb>'..fullrb..'</rb><rt><span>'..fullrt..'</span>'..(flag and fullrt2 or '')..'</rt></ruby>' end function p.main(frame) local args = getArgs(frame) if args[2] then return multi(args) else return one(args) end end return p