Module:Xpd
-- Expansion demo, like Template:Xpd
local p = {}
function p.f(frame, showwikitext, sep)
local pframe, w = frame:getParent(), { '{{' } for n,v in pairs( pframe.args ) do if type(n) == "string" then table.insert( w, table.concat({ '|', p.unexpand(n), '=', p.unexpand(v) }) ) elseif n ~= 1 then table.insert( w, table.concat({ '|', p.unexpand(v) }) ) else table.insert( w, 2, v ) end end table.insert( w, '}}' ) w = table.concat( w ) local xpw = frame:preprocess( w ) w = table.concat({ '', p.swt(w), '
→ ' }) if showwikitext then w = table.concat({ w, sep, '', p.swt( xpw ), '
→ ' }) end w = table.concat( { w, xpw }, sep ) return w
end
function p.s(frame) return p.f(frame, false, ) end function p.p(frame) return p.f(frame, false, '\n\n') end function p.ws(frame) return p.f(frame, true, ) end function p.wp(frame) return p.f(frame, true, '\n\n') end
function p.unexpand(w)
local w1 = string.gsub( w, '[{}|=]', { ['{'] = '{', ['}'] = '}', ['|'] = '|', ['='] = '=', }):gsub( 'lbrace', '{' ):gsub( 'rbrace', '}' ) return w1
end
function p.swt(w)
local w1 = string.gsub( w, '[&<>%[%] \n\']', { ['&'] = '&', ['<'] = '<', ['>'] = '>', ['['] = '[', [']'] = ']', ["'"] = ''', [' '] = ' ', ['\n'] = '
', }) return w1
end
function p.plain(frame, sep)
local w = frame:getParent().args[1]
return table.concat({ '', p.swt( p.unexpand( w ) ), '
→ ', sep, w })
end
function p.plains(frame) return p.plain(frame, ) end function p.plainp(frame) return p.plain(frame, '\n\n') end
return p