Module:Ruby:修订间差异

创建页面,内容为“local module = {} local g_frame function get_arg ( name, plain ) if g_frame.args[name] and (mw.text.trim(g_frame.args[name]) ~= '' or plain) then return mw.text.trim(g_frame.args[name]) end end function module.ruby ( frame ) local parent = frame:getParent() if parent and (parent:getTitle() == "Template:Ruby" or parent:getTitle() == "Template:Ruby/Sandbox" or parent:getTitle() == "Template:沙盒") then frame = parent end g_frame = frame local args…”
 
无编辑摘要
 
第1行: 第1行:
local module = {}
local module = {}
local g_frame
local g_frame
 
function get_arg ( name, plain )
function get_arg ( name, plain )
if g_frame.args[name] and (mw.text.trim(g_frame.args[name]) ~= '' or plain) then
if g_frame.args[name] and (mw.text.trim(g_frame.args[name]) ~= '' or plain) then
第7行: 第7行:
end
end
end
end
 
function module.ruby ( frame )
function module.ruby ( frame )
local parent = frame:getParent()
local parent = frame:getParent()
第31行: 第31行:
return module._ruby ( args, frame )
return module._ruby ( args, frame )
end
end
 
function module._ruby ( args, frame )
function module._ruby ( args, frame )
local html = mw.html.create():tag('ruby')
local html = mw.html.create():tag('ruby')
第37行: 第37行:
if args.id then html:attr('id', args.id) end
if args.id then html:attr('id', args.id) end
if args.style then html:cssText(args.style) end
if args.style then html:cssText(args.style) end
 
local rb = html:tag('rb'):attr('data-id', 'template-ruby')
local rb = html:tag('rb'):attr('data-id', 'template-ruby')
if args.rbclass then rb:addClass(args.rbclass) end
if args.rbclass then rb:addClass(args.rbclass) end
if args.rbid then rb:attr('id', args.rbid) end
if args.rbid then rb:attr('id', args.rbid) end
if args.rbsize then rb:css('font-size', args.rbsize) end
if args.rbsize then rb:css('font-size', args.rbsize) end
 
if args.rblang then
if args.rblang then
if frame then  
if frame then  
第52行: 第52行:
rb:wikitext(args.rbtext)
rb:wikitext(args.rbtext)
end
end
rb:tag('span'):addClass('template-ruby-hidden'):wikitext('('):done()
 
local rt = html:tag('rt')
local rt = html:tag('rt')
if args.rtclass then rt:addClass(args.rtclass) end
if args.rtclass then rt:addClass(args.rtclass) end
第67行: 第66行:
rt:wikitext(args.rttext)
rt:wikitext(args.rttext)
end
end
html:tag('span'):addClass('template-ruby-hidden'):wikitext(')'):done()
 
return tostring ( html )
return tostring ( html )
end
end
 
return module
return module