Module:Infobox: Difference between revisions
m
fixes for child infoboxes so HTML Tidy is not required
m>Frietjes (rowcellstyle per talk page) |
m>Jc86035 m (fixes for child infoboxes so HTML Tidy is not required) |
||
Line 10: | Line 10: | ||
local origArgs | local origArgs | ||
local root | local root | ||
local orphancat = 'Category:Orphan infoboxes' | |||
local function notempty( s ) return s and s:match( '%S' ) end | |||
local function union(t1, t2) | local function union(t1, t2) | ||
Line 43: | Line 47: | ||
-- Adds a row to the infobox, with either a header cell | -- Adds a row to the infobox, with either a header cell | ||
-- or a label/data cell combination. | -- or a label/data cell combination. | ||
local s = {} | |||
local ttype = 'td' | |||
if rowArgs.header then | |||
rowArgs.data = nil | |||
s = mw.text.split(rowArgs.header, '%[%[' .. orphancat .. '%]%]') | |||
if notempty(s[1]) then | |||
rowArgs.header = s[1] | |||
else | |||
rowArgs.header = nil | |||
end | |||
ttype = 'th' | |||
elseif rowArgs.data then | |||
s = mw.text.split(rowArgs.data, '%[%[' .. orphancat .. '%]%]') | |||
if notempty(s[1]) then | |||
rowArgs.data = s[1] | |||
else | |||
rowArgs.data = nil | |||
end | |||
ttype = 'td' | |||
end | |||
if rowArgs.header then | if rowArgs.header then | ||
root | |||
:tag('tr') | :tag('tr') | ||
:addClass(rowArgs.rowclass) | :addClass(rowArgs.rowclass) | ||
Line 73: | Line 98: | ||
:done() | :done() | ||
end | end | ||
local s = mw.text.split(rowArgs.data, '%[%[' .. orphancat .. '%]%]') | |||
rowArgs.data = s[1] | |||
local dataCell = row:tag('td') | local dataCell = row:tag('td') | ||
if not rowArgs.label then | if not rowArgs.label then | ||
Line 88: | Line 114: | ||
:wikitext(rowArgs.data) | :wikitext(rowArgs.data) | ||
end | end | ||
for i = 2, #s do | |||
if notempty(s[i]) then | |||
if (i % 2) == 0 then | |||
root | |||
:wikitext(s[i]) | |||
else | |||
local dataCell = root:tag('tr'):tag(ttype) | |||
dataCell | |||
:attr('colspan', 2) | |||
:wikitext(s[i]) | |||
end | |||
end | |||
end | |||
end | end | ||
Line 102: | Line 142: | ||
local function renderAboveRow() | local function renderAboveRow() | ||
if not args.above then return end | if not args.above then return end | ||
root | root | ||
:tag('tr') | :tag('tr') | ||
Line 231: | Line 270: | ||
-- Specify the overall layout of the infobox, with special settings | -- Specify the overall layout of the infobox, with special settings | ||
-- if the infobox is used as a 'child' inside another infobox. | -- if the infobox is used as a 'child' inside another infobox. | ||
local marker = '' | |||
if args.child ~= 'yes' then | if args.child ~= 'yes' then | ||
root = mw.html.create('table') | root = mw.html.create('table') | ||
Line 260: | Line 300: | ||
else | else | ||
root = mw.html.create() | root = mw.html.create() | ||
marker = '[[' .. orphancat .. ']]' | |||
root | root | ||
:wikitext(args.title) | :wikitext(args.title) | ||
Line 273: | Line 313: | ||
renderTrackingCategories() | renderTrackingCategories() | ||
return tostring(root) | return marker .. tostring(root) .. marker | ||
end | end | ||