Module:User:Babr/Sandbox2
Appearance
- This module sandbox lacks a documentation subpage. Please create it.
- Useful links: root page • root page’s subpages • links • transclusions • testcases • sandbox
local export = {}
function export.show(frame)
local pageContent = mw.title.new("User:Babr/Palette.css"):getContent()
local lightMode = true;
local lightModeData = {}
local darkModeData = {}
local seenVariables = {} -- In order to maintain the order.
local output = {
[=[{| class="palette-table wikitable"
|+Examples of palette variables in light and dark mode
|-
!scope="col"| Variable name
!scope="col"| Light mode
!scope="col"| Dark mode
|-"
]=]}
for line in pageContent:gmatch("[^\r\n]*") do
-- Hack to check whether we've reached the dark mode styles.
if line == "@media screen {" then
lightMode = false;
end
local definedVariable = line:match("--wikt%-palette%-[a-z]+")
if definedVariable then
if lightMode then
table.insert(seenVariables, definedVariable)
lightModeData[definedVariable] = line:match("#[a-zA-Z0-9]+")
else
darkModeData[definedVariable] = line:match("#[a-zA-Z0-9]+")
end
end
end
for _, var in ipairs(seenVariables) do
table.insert(output, "|<code>" .. var .. "</code>")
table.insert(output, "||style=\"background-color:" .. lightModeData[var] .. "\"|<span class=\"palette-highlight\">" .. lightModeData[var] .. "</span>")
table.insert(output, "||style=\"background-color:" .. darkModeData[var] .. "\"|<span class=\"palette-highlight\">" .. darkModeData[var] .. "</span>")
table.insert(output, "\n|-\n")
end
table.insert(output, "\n|}")
table.insert(output, frame:extensionTag("templatestyles", "", {src="Module:palette/styles.css"}))
return table.concat(output)
end
return export