Module:Tt/Draft: Difference between revisions
No edit summary |
No edit summary |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 19: | Line 19: | ||
function p._main(args, options) | function p._main(args, options) | ||
local text = args[1] | local text = args[1] | ||
local tooltip = args[2] | local tooltip = mw.text.decode(args[2], true) | ||
local header = lib.isNotEmpty(args.header) and args.header or nil | local header = lib.isNotEmpty(args.header) and mw.text.decode(args.header, true) or nil | ||
local class = lib.isNotEmpty(args.class) and args.class .. ' custom-tt-wrapper toggle-tooltip' or 'custom-tt-wrapper toggle-tooltip' | |||
local out = mw.html.create() | local out = mw.html.create() | ||
| Line 33: | Line 34: | ||
-- Build toggle tooltip | -- Build toggle tooltip | ||
local toggle = out:tag('span'):addClass( | local toggle = out:tag('span'):addClass(class) | ||
-- Optional toggleable text but plain text must be there for gadget | -- Optional toggleable text but plain text must be there for gadget | ||
| Line 75: | Line 76: | ||
local full = tx | local full = tx | ||
local result = tx | local result = tx | ||
for display in string.gmatch(full, | |||
for display | '<span[^>]*class="[^"]*custom%-tt%-wrapper[^"]*"[^>]*>' .. | ||
'<span[^>]*class="[^"]*mw%-collapsible%-toggle[^"]*"[^>]*>(.-)</span>' .. | |||
'<span[^>]*class="[^"]*mw%-collapsible%-content[^"]*"[^>]*>.-</span></span>' | |||
) do | |||
local escDisplay = display:gsub("([^%w])", "%%%1") | local escDisplay = display:gsub("([^%w])", "%%%1") | ||
search_str = '<span class=" | local search_str = | ||
'<span[^>]*class="[^"]*custom%-tt%-wrapper[^"]*"[^>]*>' .. | |||
'<span[^>]*class="[^"]*mw%-collapsible%-toggle[^"]*"[^>]*>' .. escDisplay .. '</span>' .. | |||
'<span[^>]*class="[^"]*mw%-collapsible%-content[^"]*"[^>]*>.-</span></span>' | |||
result = result:gsub(search_str, display) | result = result:gsub(search_str, display) | ||
end | end | ||