Module:TemplateStructure: Difference between revisions
No edit summary Tag: Reverted |
No edit summary Tag: Reverted |
||
| Line 5: | Line 5: | ||
Renders a table using a modular, block-based approach via the HTML builder API. | Renders a table using a modular, block-based approach via the HTML builder API. | ||
This version generates an explicit <table> element with its rows inserted as | This version generates an explicit <table> element with its rows inserted as unescaped wikitext, | ||
so that MediaWiki’s parser won’t inject unwanted <p> or <br> elements. | so that MediaWiki’s parser won’t inject unwanted <p> or <br> elements. | ||
| Line 24: | Line 24: | ||
config = config or {} | config = config or {} | ||
local tableClass = config.tableClass or "template-table" | local tableClass = config.tableClass or "template-table" | ||
local tableAttrs = config.tableAttrs or { cellpadding = "2" } | local tableAttrs = config.tableAttrs or { cellpadding = "2" } | ||
local blocks = config.blocks or {} | local blocks = config.blocks or {} | ||
| Line 32: | Line 31: | ||
tableEl:attr("class", tableClass) | tableEl:attr("class", tableClass) | ||
-- Process each block function and insert its output as | -- Process each block function and insert its output as unescaped wikitext. | ||
for i, block in ipairs(blocks) do | for i, block in ipairs(blocks) do | ||
if type(block) == "function" then | if type(block) == "function" then | ||
local blockOutput = block(args, config) | local blockOutput = block(args, config) | ||
if blockOutput and blockOutput ~= "" then | if blockOutput and blockOutput ~= "" then | ||
tableEl: | tableEl:wikitext(blockOutput) | ||
end | end | ||
else | else | ||