Permanently protected module

Difference between revisions of "Module:Ruby"

From Yugipedia
Jump to: navigation, search
("implements" comment)
(add some newlines)
Line 10: Line 10:
 
         return
 
         return
 
     end
 
     end
 +
 
     args[1] = mw.text.trim( args[1] )
 
     args[1] = mw.text.trim( args[1] )
 +
 
     if not mw.ustring.find( args[1], '<ruby' ) then
 
     if not mw.ustring.find( args[1], '<ruby' ) then
 
         return args[1]
 
         return args[1]
 
     end
 
     end
 +
 
     args[2] = args[2] or ''
 
     args[2] = args[2] or ''
 
     args[2] = args[2] == 'base' and '' or args[2]
 
     args[2] = args[2] == 'base' and '' or args[2]
 +
 
     local first, parts, match
 
     local first, parts, match
 
     first = mw.ustring.match( args[1], '^([^<]*)' ) or ''
 
     first = mw.ustring.match( args[1], '^([^<]*)' ) or ''
Line 25: Line 29:
 
                 .. ( mw.ustring.match( parts[i], '</ruby>(.*)$' ) or '' )
 
                 .. ( mw.ustring.match( parts[i], '</ruby>(.*)$' ) or '' )
 
     end
 
     end
 +
 
     return first, table.concat( parts, '' )
 
     return first, table.concat( parts, '' )
 
end
 
end
  
 
return p
 
return p

Revision as of 00:03, 3 March 2015

local p = {}

function p.split( frame )
    --
    -- implements {{Ruby/split}}
    --

    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 first, parts, match
    first = mw.ustring.match( args[1], '^([^<]*)' ) or ''
    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 ) or '' )
                .. ( mw.ustring.match( parts[i], '</ruby>(.*)$' ) or '' )
    end

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

return p