Module:Capitalize

From Wikidata
Jump to navigation Jump to search
Lua
CodeDiscussionLinksLink count SubpagesDocumentationTestsResultsSandboxLive code All modules

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

Code

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