Module:User:Surjection/script utilities/tag text

Hello, you have come here looking for the meaning of the word Module:User:Surjection/script utilities/tag text. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:User:Surjection/script utilities/tag text, but we will also tell you about its etymology, its characteristics and you will know how to say Module:User:Surjection/script utilities/tag text in singular and plural. Everything you need to know about the word Module:User:Surjection/script utilities/tag text you have here. The definition of the word Module:User:Surjection/script utilities/tag text will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:User:Surjection/script utilities/tag text, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.


local export = {}

-- Wrap text in the appropriate HTML tags with language and script class.
function export.tag_text(text, lang, sc, face, class, id)
	if not sc then
		sc = require("Module:scripts").findBestScript(text, lang)
	end
	
	track(text, lang, sc)
	
	-- Replace space characters with newlines in Mongolian-script text, which is written top-to-bottom.
	if sc:getDirection() == "down" and text:find(" ") then
		text = require("Module:munge_text")(text, function(txt)
			-- having extra parentheses makes sure only the first return value gets through
			return (txt:gsub(" +", "<br>"))
		end)
	end

	-- Hack Korean script text to remove hyphens.
	-- This should be handled in a more general fashion, but needs to
	-- be efficient by not doing anything if no hyphens are present, and currently this is the only
	-- language needing such processing.
	if sc:getCode() == "Kore" and text:find("%-") then
		text = require("Module:munge_text")(text, function(txt)
			-- having extra parentheses makes sure only the first return value gets through
			return (txt:gsub("%-", ""))
		end)
	end
	
	if sc:getCode() == "Imag" then
		face = nil
	end

	if face == "hypothetical" then
	-- ]
		require("Module:debug/track")("script-utilities/face/hypothetical")
	end
	
	local data = mw.loadData("Module:script utilities/data").faces
	if not data then
		error('Invalid script face "' .. face .. '".')
	end
	
	local post = ""
	if sc:getDirection() == "rtl" and (face == "translation" or mw.ustring.find(text, "%p$")) then
		post = "&lrm;"
	end
	
	-- Add a script wrapper
	
	-- classes
	local result = ( data.prefix or "" ) .. '<' .. data.tag .. ' class="' .. sc:getCode()
	if data.class then
		result = result .. ' ' .. data.class
	end
	if class and class ~= '' then
		result = result .. ' ' .. class
	end
	result = result .. '"'
	
	if id then -- id
		result = result .. ' id="' .. require("Module:senseid").anchor(lang, id) .. '"'
	end
	if lang then -- lang
		result = result .. ' lang="' .. lang:getCode() .. '"'
	end
	
	return result .. '>' .. text .. '</' .. data.tag .. '>' .. post
end

return export