Module:TemplateStructure: Difference between revisions
// via Wikitext Extension for VSCode |
// via Wikitext Extension for VSCode |
||
| Line 32: | Line 32: | ||
function p.render(args, config, errorContext) | function p.render(args, config, errorContext) | ||
config = config or {} | config = config or {} | ||
local ariaLabelledBy = config.ariaLabelledBy and string.format('aria-labelledby="%s"', config.ariaLabelledBy) or '' | |||
-- Support fullPage mode: render blocks inside a <div> wrapper when requested | -- Support fullPage mode: render blocks inside a <div> wrapper when requested | ||
| Line 39: | Line 40: | ||
-- open container without default template-table class when empty | -- open container without default template-table class when empty | ||
local cls = config.tableClass or '' | local cls = config.tableClass or '' | ||
local attr = {ariaLabelledBy} | |||
if cls ~= '' then | if cls ~= '' then | ||
table.insert( | table.insert(attr, 1, string.format('class="%s"', cls)) | ||
end | end | ||
table.insert(out, string.format('<%s %s>', tag, table.concat(attr, ' '))) | |||
for i, block in ipairs(config.blocks or {}) do | for i, block in ipairs(config.blocks or {}) do | ||
local ok, blk = pcall(block, args, config) | local ok, blk = pcall(block, args, config) | ||
| Line 70: | Line 72: | ||
-- Begin the table markup | -- Begin the table markup | ||
local result = {} | local result = {} | ||
table.insert(result, string.format('{| class="%s" %s', tableClass, tableAttrs)) | table.insert(result, string.format('{| class="%s" %s %s', tableClass, tableAttrs, ariaLabelledBy)) | ||
-- Process each block function in the supplied order | -- Process each block function in the supplied order | ||
| Line 127: | Line 129: | ||
-- Renders a standard title block with configurable class and text (basic version) | -- Renders a standard title block with configurable class and text (basic version) | ||
function p.renderTitleBlock(args, titleClass, titleText) | function p.renderTitleBlock(args, titleClass, titleText, titleId) | ||
titleClass = titleClass or "template-title" | titleClass = titleClass or "template-title" | ||
return string.format('|-\n! colspan="2" class="%s" | %s', titleClass, | local idAttr = titleId and string.format('id="%s"', titleId) or '' | ||
local titleSpan = string.format('<span %s>%s</span>', idAttr, titleText) | |||
return string.format('|-\n! colspan="2" class="%s" | %s', titleClass, titleSpan) | |||
end | end | ||