Module:Sandbox/Gonnym/Script basic documentation: Difference between revisions
Appearance
Content deleted Content added
No edit summary |
No edit summary |
||
Line 18: | Line 18: | ||
function p.main(frame) |
function p.main(frame) |
||
local |
local page = mw.title.getCurrentTitle() |
||
local pageName = mw.ustring.lower(title.subpageText) |
|||
local styles = "Template:Script/styles " .. |
local styles = "Template:Script/styles " .. pageName .. ".css" |
||
local text = mw.title.new(styles):getContent() |
local text = mw.title.new(styles):getContent() |
||
Line 27: | Line 27: | ||
return table.concat(fonts, ", ") |
return table.concat(fonts, ", ") |
||
else |
else |
||
extractFontNames( |
extractFontNames(page:getContent()) |
||
return table.concat(fonts, ", ") |
return table.concat(fonts, ", ") |
||
end |
end |
Revision as of 12:32, 6 June 2024
require("strict")
--- @module
local p = {}
local function extractFontNames(text)
local fontNames = {}
for fonts in text:gmatch("font%-family:%s*([^;}]+);") do
for font in fonts:gmatch("([^,]+)") do
font = font:match("^%s*(.-)%s*$") -- Trim leading and trailing whitespace
font = font:gsub('"', "") -- Remove double quotes
font = font:gsub("'", "") -- Remove single quotes
table.insert(fontNames, font)
end
end
return fontNames
end
function p.main(frame)
local page = mw.title.getCurrentTitle()
local pageName = mw.ustring.lower(title.subpageText)
local styles = "Template:Script/styles " .. pageName .. ".css"
local text = mw.title.new(styles):getContent()
if text then
local fonts = extractFontNames(text)
return table.concat(fonts, ", ")
else
extractFontNames(page:getContent())
return table.concat(fonts, ", ")
end
return nil
end
return p