Difference between revisions of "Module:Capitalize"

From DiSSCo Modelling Framework
Jump to navigation Jump to search
wd>TomT0m
(cap after the tags)
 
m (1 revision imported: Import of useful Templates and Modules from Wikidata)
 
(No difference)

Latest revision as of 20:47, 6 January 2022

Documentation for this module may be created at Module:Capitalize/doc

local p = {}

function p.cap(str)
	lang = mw.getContentLanguage()
	if lang:ucfirst(str) ~= str then
		return lang:ucfirst(str)
	else
		local substr = mw.ustring.sub 
		b, e = mw.ustring.find(str, ">%s*%a")
		while e ~= nil do
			if mw.ustring.find(">", substr(str, b,e)) == nil then 
				return substr(str, 1, e-1) .. lang:ucfirst(substr(str,e,e)) ..substr(str, e+1)
			end
			b, e = mw.ustring.find(str, ">%s*%a", e)
		end
		return str
	end
end

function p.capitalize(frame) return p.cap(frame.args[1]) end

return p