Мазмунга өтүү

Модуль:ko/multi

Wiktionary дан

Documentation for this module may be created at Модуль:ko/multi/doc

local export = {}

local m_template_parser = require("Module:template parser")

local class_else_type = m_template_parser.class_else_type
local ko_link = require("Module:ko").link
local parse = m_template_parser.parse
local pcall = pcall

function export.main(frame)
	local text = frame:getParent().args["data"]
	if not text then
		return ""
	end
	
	text = parse(frame:getParent().args["data"])
	for node, parent, key in text:__pairs("next_node") do
		local class = class_else_type(node)
		if class ~= "wikitext" then
			local new
			if class == "template" and node:get_name() == "ko-l" then
				local success, result = pcall(ko_link, node:get_arguments(), lang)
				if success then
					new = result
				end
			end
			if not new then
				new = node:expand()
			end
			if parent then
				parent[key] = new
			else
				text = new
			end
		end
	end
	return tostring(text)
end

return export