Modul:Infobox: Unterschied zwischen den Versionen
Keine Bearbeitungszusammenfassung |
KKeine Bearbeitungszusammenfassung |
||
| Zeile 29: | Zeile 29: | ||
header:attr("role", "heading") | header:attr("role", "heading") | ||
header:attr("aria-level", 1) | header:attr("aria-level", 1) | ||
header:addClass(" | header:addClass("infobox__main-header") | ||
header:wikitext(args.header) | header:wikitext(args.header) | ||
section:node(header) | section:node(header) | ||
| Zeile 85: | Zeile 85: | ||
header:attr("role", "heading") | header:attr("role", "heading") | ||
header:attr("aria-level", 2) | header:attr("aria-level", 2) | ||
header:addClass(" | header:addClass("infobox__section-header") | ||
header:wikitext(args.header) | header:wikitext(args.header) | ||
section:node(header) | section:node(header) | ||
Version vom 17. September 2024, 21:21 Uhr
Die Dokumentation für dieses Modul kann unter Modul:Infobox/Doku erstellt werden
local argutils = require("Module:Arguments")
local M = {}
local function build_image(args)
local figure = mw.html.create("figure")
figure:addClass("infobox__image")
if args.image then
figure:wikitext(args.image)
end
if args.caption then
local caption = mw.html.create("figcaption")
caption:addClass("infobox__image-caption")
caption:wikitext(args.caption)
figure:node(caption)
end
return figure
end
local function build_main_section(args)
local section = mw.html.create("div")
section:addClass("infobox__section")
if args.header ~= nil then
local header = mw.html.create("div")
header:attr("role", "heading")
header:attr("aria-level", 1)
header:addClass("infobox__main-header")
header:wikitext(args.header)
section:node(header)
end
if args.subheader ~= nil then
local subheader = mw.html.create("p")
subheader:addClass("infobox__subheader")
subheader:wikitext(args.subheader)
section:node(subheader)
end
if args.images ~= nil then
for _, image_args in ipairs(args.images) do
section:node(build_image(image_args))
end
end
return section
end
local function build_section_entry(args)
if type(args) == "string" then
local div = mw.html.create("div")
div:addClass("infobox__section-entry")
div:wikitext(args)
return div
else
local dl = mw.html.create("dl")
dl:addClass("infobox__section-entry")
if args.label ~= nil then
local dt = mw.html.create("dt")
dt:addClass("infobox__section-entry-label")
dt:wikitext(args.label)
dl:node(dt)
end
if args.text ~= nil then
local dd = mw.html.create("dd")
dd:addClass("infobox__section-entry-text")
dd:wikitext(args.text)
dl:node(dd)
end
return dl
end
end
local function build_section(args)
local section = mw.html.create("div")
section:addClass("infobox__section")
if args.header ~= nil then
local header = mw.html.create("div")
header:attr("role", "heading")
header:attr("aria-level", 2)
header:addClass("infobox__section-header")
header:wikitext(args.header)
section:node(header)
end
if args.entries ~= nil then
for _, entry_args in ipairs(args.entries) do
section:node(build_section_entry(entry_args))
end
end
return section
end
local function build(args)
local wrapper = mw.html.create("div")
wrapper:attr("role", "aside")
wrapper:addClass("infobox")
wrapper:node(build_main_section(args))
if args.sections ~= nil then
for _, section_args in ipairs(args.sections) do
wrapper:node(build_section(section_args))
end
end
return wrapper
end
function M.render(frame)
local parentFrame = frame:getParent() or {}
local flat_args = parentFrame.args or {}
local args = argutils.parse_deep(flat_args)
return tostring(build(args))
end
return M