local p = {}
function p.split( frame )
--
-- implements {{Ruby/split}}
--
local args = frame == mw.getCurrentFrame() and frame:getParent().args or frame
if not args or not args[1] then
return -- nothing was passed to the module
end
if not args[1]:find( '<ruby' ) then
return args[1] -- if there's no Ruby markup in the input, just return it
end
local str = mw.text.trim( args[1] )
local el = 'rb'
if args[2] and not args[2]:find( 'base' ) then
el = 'rt'
end
local out = {}
table.insert( out, str:match( '^(.-)<ruby' ) ) -- grab anything before the first <ruby> tag
for piece in mw.text.gsplit( str, '<ruby' ) do
table.insert( out, table.concat( { piece:match( ( '<%s[^>]*>(.-)</%s>' ):format( el, el ) ), piece:match( '</ruby>(.-)$' ) } ) )
end
return table.concat( out, '' )
end
return p