Jump to content

Module:Sandbox/Gonnym/Script basic documentation: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
No edit summary
No edit summary
Line 7: Line 7:
local fontNames = {}
local fontNames = {}
for fonts in text:gmatch("font%-family:%s*([^;}]+);") do
for fonts in text:gmatch("font%-family:%s*([^;}]+);") do
for font in fonts:gmatch("([^,%s]+)") do
for font in fonts:gmatch("([^,]+)") do
font = font:match("^%s*(.-)%s*$") -- Trim leading and trailing whitespace
table.insert(fontNames, font)
table.insert(fontNames, font)
end
end

Revision as of 12:24, 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
			table.insert(fontNames, font)
		end
	end
	return fontNames
end

function p.main(frame)
	local title = mw.title.getCurrentTitle().subpageText
	title = mw.ustring.lower(title)
	local styles = "Template:Script/styles " .. title .. ".css"
	local text = mw.title.new(styles):getContent()

	if text then
		local fonts = extractFontNames(text)
		return table.concat(fonts, ", ")
	end
	return nil
end

return p