Modul:Navbox: Unterschied zwischen den Versionen
find vanishing TemplateStyles in args, find plainlist in class args
(remove titlegroup per templatestyles section on talk page) |
(find vanishing TemplateStyles in args, find plainlist in class args) |
||
Zeile 285: | Zeile 285: | ||
end | end | ||
return false | return false | ||
end | |||
-- there are a lot of list classes in the wild, so we add their TemplateStyles | |||
local function add_list_styles() | |||
local function add_list_templatestyles(htmlclass, templatestyles) | |||
local frame = mw.getCurrentFrame() | |||
if has_list_class(htmlclass) then | |||
return frame:extensionTag{ | |||
name = 'templatestyles', args = { src = templatestyles } | |||
} | |||
else | |||
return '' | |||
end | |||
end | |||
-- TODO: get hlist to the point where we can do this for hlist | |||
-- see [[MediaWiki talk:Common.css/to do#Hlist]] | |||
local plainlist_styles = add_list_templatestyles('plainlist', 'Plainlist/styles.css') | |||
return plainlist_styles | |||
end | end | ||
Zeile 387: | Zeile 407: | ||
end | end | ||
local function add_navbox_styles() | local function add_navbox_styles(hiding_templatestyles) | ||
local frame = mw.getCurrentFrame() | local frame = mw.getCurrentFrame() | ||
-- This is a lambda so that it doesn't need the frame as a parameter | -- This is a lambda so that it doesn't need the frame as a parameter | ||
Zeile 405: | Zeile 425: | ||
local child_templatestyles = add_user_styles(args[cfg.arg.child_templatestyles]) | local child_templatestyles = add_user_styles(args[cfg.arg.child_templatestyles]) | ||
-- The 'navbox-styles' div exists | -- The 'navbox-styles' div exists to wrap the styles to work around T200206 | ||
-- more elegantly. Instead of combinatorial rules, this ends up being linear | |||
-- number of CSS rules. | |||
return mw.html.create('div') | return mw.html.create('div') | ||
:addClass(cfg.class.navbox_styles) | :addClass(cfg.class.navbox_styles) | ||
: | :wikitext( | ||
base_templatestyles .. | |||
templatestyles .. | |||
child_templatestyles .. | |||
add_list_styles() .. | |||
table.concat(hiding_templatestyles) | |||
) | |||
:done() | :done() | ||
end | |||
-- work around [[phab:T303378]] | |||
-- for each arg: find all the templatestyles strip markers, insert them into a | |||
-- table. then remove all templatestyles markers from the arg | |||
local function move_hiding_templatestyles(args) | |||
local gfind = string.gfind | |||
local gsub = string.gsub | |||
local templatestyles_markers = {} | |||
local strip_marker_pattern = '(\127[^\127]*UNIQ%-%-templatestyles%-%x+%-QINU[^\127]*\127)' | |||
for k, arg in pairs(args) do | |||
for marker in gfind(arg, strip_marker_pattern) do | |||
table.insert(templatestyles_markers, marker) | |||
end | |||
args[k] = gsub(arg, strip_marker_pattern, '') | |||
end | |||
return templatestyles_markers | |||
end | end | ||
function p._navbox(navboxArgs) | function p._navbox(navboxArgs) | ||
args = navboxArgs | args = navboxArgs | ||
local hiding_templatestyles = move_hiding_templatestyles(args) | |||
local listnums = {} | local listnums = {} | ||
Zeile 441: | Zeile 482: | ||
if border == cfg.keyword.border_none then | if border == cfg.keyword.border_none then | ||
res:node(add_navbox_styles()) | res:node(add_navbox_styles(hiding_templatestyles)) | ||
local nav = res:tag('div') | local nav = res:tag('div') | ||
:attr('role', 'navigation') | :attr('role', 'navigation') | ||
Zeile 467: | Zeile 508: | ||
:wikitext('<div>') | :wikitext('<div>') | ||
else | else | ||
res:node(add_navbox_styles()) | res:node(add_navbox_styles(hiding_templatestyles)) | ||
local nav = res:tag('div') | local nav = res:tag('div') | ||
:attr('role', 'navigation') | :attr('role', 'navigation') |