Jump to content

Module:Sandbox/Gonnym/Script basic documentation

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Gonnym (talk | contribs) at 12:02, 6 June 2024. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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("[^,%s]+") do
            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