Permanently protected module

Module:Ruby

From Yugipedia
Revision as of 22:52, 2 March 2015 by Dinoguy1000 (talk | contribs) (second argument can be "base", in which case it should return the base text, not the furigana)
Jump to: navigation, search
local p = {}

function p.split( frame )
    local args = frame:getParent().args
    if not args[1] then
        return
    end
    args[1] = mw.text.trim( args[1] )
    if not mw.ustring.find( args[1], '<ruby' ) then
        return args[1]
    end
    args[2] = args[2] or ''
    args[2] = args[2] == 'base' and '' or args[2]
    local parts, match
    parts = mw.text.split( args[1], '<ruby' )
    match = mw.text.trim( args[2] ) ~= '' and '<rb>([^<]*)</rb>' or '<rt>([^<]*)</rt>'

    for i=1, #parts do
        parts[i] = mw.ustring.match( parts[i], match ) .. mw.ustring.match( parts[i], '</ruby>(.*)$' )
    end
    return table.concat( parts, '' )
end

return p