LLWiki正在建设中,欢迎加入我们!
模块:Photrans
跳转到导航
跳转到搜索
可在模块:Photrans/doc创建此模块的帮助文档
local p = {} local getArgs = require('module:arguments').getArgs function main(args) local rb = args[1] local rt = args[2] local newrb = '' local newrt = '' if rt then local lrb = mw.ustring.len(rb) local lrt = mw.ustring.len(rt) local diff = lrt * 0.75 - lrb local space = '' if diff > 0 then space = tostring(math.floor(diff / (lrb + 1) * 1000) / 1000)..'em' newrb = '<span style="margin-left:'..space..';letter-spacing:'..space..'">'..rb..'</span>' newrt = rt else space = tostring(math.floor(-diff / (lrt + 1) / 0.75 * 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 end function p.one(frame) local args = getArgs(frame) 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 p.multi(frame) local fullrb = '' local fullrt = '' for k, v in ipairs(getArgs(frame)) do local args = mw.text.split(v, '_') local newrb, newrt = main(args) fullrb = fullrb..newrb fullrt = fullrt..newrt end return '<ruby><rb>'..fullrb..'</rb><span>(</span><rt><span>'..fullrt..'</span></rt><span>)</span></ruby>' end return p