Difference between revisions of "Module:Ruby"
Dinoguy1000 (talk | contribs) (from sandbox - fix frame stuff to allow calling in templates or via invocation in other modules; make it work even when there's weird stuff going on in the <rb>/<rt> tags (as some wikis reusing this want to do)) |
Dinoguy1000 (talk | contribs) (from sandbox - allow arbitrary markup in/around the ruby markup) |
||
Line 24: | Line 24: | ||
local first, parts, match | local first, parts, match | ||
− | first = mw.ustring.match( args[1], '^( | + | first = mw.ustring.match( args[1], '^(.-)<ruby' ) or '' |
parts = mw.text.split( args[1], '<ruby' ) | parts = mw.text.split( args[1], '<ruby' ) | ||
− | match = args[2] == '' and '<rb[^>]*>( | + | match = args[2] == '' and '<rb[^>]*>(.-)</rb>' or '<rt[^>]*>(.-)</rt>' |
− | for i=1, #parts do | + | for i = 1, #parts do |
parts[i] = ( mw.ustring.match( parts[i], match ) or '' ) | parts[i] = ( mw.ustring.match( parts[i], match ) or '' ) | ||
.. ( mw.ustring.match( parts[i], '</ruby>(.*)$' ) or '' ) | .. ( mw.ustring.match( parts[i], '</ruby>(.*)$' ) or '' ) |
Revision as of 17:06, 25 July 2016
local p = {}
function p.split( frame )
--
-- implements {{Ruby/split}}
--
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], '<ruby' ) then
return args[1]
end
args[2] = args[2] and ( mw.text.trim( args[2] ) == 'base' and '' or mw.text.trim( args[2] ) ) or ''
local first, parts, match
first = mw.ustring.match( args[1], '^(.-)<ruby' ) or ''
parts = mw.text.split( args[1], '<ruby' )
match = 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