Module:User:Victar/desctree2

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


local export = {}

function export.getAlternativeForms(lang, term)
	local page = mw.title.new(require("Module:links").getLinkPage(term, lang))
	local content = page:getContent()
	
	if not content then
		return ""
	end
	
	local _, index = mw.ustring.find(content, "\n==" .. lang:getCanonicalName() .. "==", nil, true)
	if not index then
		_, index = mw.ustring.find(content, "^==" .. require("Module:utilities").pattern_escape(lang:getCanonicalName()) .. "==", nil, false)
	end
	if not index then
		error("Language not found: " .. lang:getCanonicalName() .. ".")
	end
	_, next_lang = mw.ustring.find(content, "\n==+==", index, false)
	_, index = mw.ustring.find(content, "\n(=====?)Alternative forms%1", index, false)
	index = mw.ustring.find(content, "{{alter|" .. lang:getCode() .. "|+", index)
	if (not index) or (next_lang and next_lang < index) then
		return ""
	end
	
	local next_section = mw.ustring.find(content, "\n(=+)+%1", index)
	
	local alternative_forms_section = mw.ustring.sub(content, index, next_section)
	
	mw.log(alternative_forms_section)
	
	local terms_list = {}
	
	for alternative_form_template in mw.ustring.gmatch(alternative_forms_section, "{{alter|+}}") do
		local terms
		if mw.ustring.find(alternative_form_template, "||") then
			terms = mw.ustring.match(alternative_form_template, "{{alter|" .. lang:getCode() .. "|(.+)||")
		else
			terms = mw.ustring.match(alternative_form_template, "{{alter|" .. lang:getCode() .. "|(.+)}}")
		end
		
		terms_list = mw.text.split(terms, "|")
	end
	
	if #terms_list == 0 then
		return ""
	end
	
	for i, term in ipairs(terms_list) do
		terms_list = require("Module:links").full_link{term = term, lang = lang}
	end
	
	return ", " .. table.concat(terms_list, ", ")
end

function export.getDescendants(lang, term)
	local page = mw.title.new(require("Module:links").getLinkPage(term, lang))
	local content = page:getContent()
	
	if not content then
		return ""
	end
	
	local _, index = mw.ustring.find(content, "\n==" .. lang:getCanonicalName() .. "==", nil, true)
	if not index then
		_, index = mw.ustring.find(content, "^==" .. require("Module:utilities").pattern_escape(lang:getCanonicalName()) .. "==", nil, false)
	end
	if not index then
		error("Language not found: " .. lang:getCanonicalName() .. ".")
	end
	_, next_lang = mw.ustring.find(content, "\n==+==", index, false)
	_, index = mw.ustring.find(content, "\n(=====?)Descendants%1", index, false)
	if (not index) or (next_lang and next_lang < index) then
		error("Descendants not found")
	end
	
	local asterisks, item
	local count = 0
	local items = {}
	
	while mw.ustring.sub(content, index + 1, index + 2) == "\n*" do
		_, index, item = mw.ustring.find(content, "\n(%*+)", index)
		
		-- Preprocess, but replace recursive calls to avoid template loop errors
		item = mw.ustring.gsub(item, "{{desctree|", "{{#invoke:descendants tree/templates|show|")
		item = mw.getCurrentFrame():preprocess(item)
		
		-- Parse the list item
		asterisks, item = mw.ustring.match(item, "^(%*+:?) *(.-)$")
		item = "<li>" .. item
		
		local newcount = mw.ustring.len(asterisks)
		
		if newcount > count then
			while newcount > count do
				item = "<ul>" .. item
				count = count + 1
			end
		else
			item = "</li>" .. item
		end
		
		while newcount < count do
			item = "</li></ul>" .. item
			count = count - 1
		end

		table.insert(items, item)
	end
	
	while 0 < count do
		table.insert(items, "</li></ul>")
		count = count - 1
	end
	
	return table.concat(items)
end

return export