LLWiki正在建设中,欢迎加入我们

“模块:Photrans”的版本间差异

来自LLWiki
跳转到导航 跳转到搜索
第32行: 第32行:
local rt = args[2] or ' '
local rt = args[2] or ' '
local rt2 = args[3]
local rt2 = args[3]
return '<ruby><rb>'..rb..'</rb><rt'..(rt2 and '>' or ' class="photrans-s">')..
return '<ruby><rb>'..rb..'</rb><rt'..(args[2] and '>' or ' class="photrans-s">')..
(rt2 and rt or '<span>'..rt..'</span>')..'</rt></ruby>'
(rt2 and rt or '<span>'..rt..'</span>')..'</rt></ruby>'
end
end

2022年1月14日 (五) 02:28的版本

可在模块: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]
	local rt = args[2] or '&nbsp;'
	local rt2 = args[3]
	return '<ruby><rb>'..rb..'</rb><rt'..(args[2] and '>' or ' class="photrans-s">')..
		(rt2 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(mw.text.split(args[1], '_'))
	end
end
return p