Module:Ruby

local Ruby = {} local getArgs = require('Dev:Arguments').getArgs local HF = require('Module:HF')

function Ruby.ruby (frame) local args = getArgs(frame, {   	trim = true,    	removeBlanks = false    }) return Ruby._ruby(args) end

function Ruby._ruby (args) local rubytag = mw.html.create('ruby') local lang = args['lang'] or 'ja' local link = args['link'] rubytag:addClass('rubytext'):addClass('ruby-'..lang):attr('lang', lang) for i,v in ipairs(args) do       --if (i % 2 ~= 0) and (type(args[i + 1]) ~= string) then --   rubytag:wikitext(v) --else if (i % 2 ~= 0) then rubytag:tag('rb'):wikitext(v):done elseif (i % 2 == 0) and ((type(v) == nil) or            mw.ustring.len( mw.text.trim( v ) ) == 0) then else rubytag:tag('rp'):wikitext(' ('):done           rubytag:tag('rt'):wikitext(v):done            rubytag:tag('rp'):wikitext(') '):done end end rubytag:allDone return link and HF.Link(link, tostring(rubytag)) or tostring(rubytag) --[==[   --]==] end

function Ruby.split( frame ) --   -- implements --

if frame == mw.getCurrentFrame then args = frame:getParent.args else args = frame end if not args[1] then return end

args[1] = mw.text.trim( args[1] )

if not mw.ustring.find( args[1], ']*>(.-)' or ']*>(.-)'

for i = 1, #parts do       parts[i] = ( mw.ustring.match( parts[i], match ) or '' ) .. ( mw.ustring.match( parts[i], ' (.*)$' ) or '' ) end

return first, table.concat( parts, '' ) end

return Ruby