Module:Wikitable
Jump to navigation
Jump to search
Usage
This module[1] is designed to make passing tables to templates less of a hassle.
Often time, adding wikitable markup to a template or other parser tag generates gibberish when one fails to escape every | and =. Moreover, escaping pipe characters with {{!}} everywhere can make for some rather ugly-looking markup.
With this module, most wikitables can be embedded into templates without escaping any pipe characters. Also, = for <table> element attributes do not need to be escaped, however, for individual rows and cells, such is still necessary. Finally, there must be at least one pipe character before the first header cell (only an issue if |- is omitted before the first row)
local p = {};
local getArgs = require('Module:Arguments').getArgs
local buffer = require("Module:Buffer")('{|')
function p.main(frame)
local args = getArgs(frame, {removeBlanks=false, trim=false} )
for k, v in pairs(args) do
if type(k) ~= 'number' then buffer:_(string.format(string.match(v, '^["\']') and ' %s=%s' or ' %s="%s"', k, v)) end
end
buffer:_'\n'
for _, v in ipairs(args) do
if not string.match(v, '^!') then buffer:_'|' end
buffer:_(v)
end
return table.concat(buffer:_'\n|}')
end
return p;