Preskočiť na obsah

Modul:Význam

Zo stránky Wikislovník

Backend pre Šablóna:Význam.


export = {}

export.delimers={
	[' ']=1,
	['\t']=1,
	['-']=1,
	['.']=1,
	[',']=1,
	[';']=1,
	['+']=1,
	['−']=1,
	['*']=1,
	['/']=1,
	['=']=1,
	['?']=1,
	['!']=1,
	['(']=1,
	[')']=1,
	['{']=1,
	['}']=1,
	['<']=1,
	['>']=1,
	['@']=1,
	['^']=1,
	['`']=1,
	["'"]=1,
	['"']=1,
	['„']=1,
	['“']=1,
	['|']=1,
	['~']=1,
}

function export.is_delimer(text,offset,length)
	local o=offset
	local output=""
	while o < length do
		local char=string.sub(text,o,o)
		if export.delimers[char] == nil then
			break
		end
		output=output..char
		o=o+1
	end
	
	return output
end

function export.is_term(text,offset,offset_after)
	local o=offset
	local output=""
	local End
	local char
	
	while o < offset_after do
		char=string.sub(text,o,o)
		if char == "[" and string.sub(text,o,o+1) == "[[" then
			End=string.find(text, "]]", o)
			if End == nil then
				error("unclosed link")
			end
			
			output=output..string.sub(text,o,End+1)
			o=End+2
		else
			if export.delimers[char] then
				break
			end
			output=output..char
			o=o+1
		end
		
	end
	
	return output
end

function export.text2wikilinks(text)
	local offset_after
	local o
	local value
	local output=""
	local start
	
	offset_after=string.len(text)+1
	
	o=1
	while o < offset_after do
		while 1 do
			value=export.is_term(text,o,offset_after);
			if value ~= "" then
				offset=string.find(value, "%[%[");
				if offset then
					output=output..value
				else
					output=output.."[["..value.."]]"
				end
				
				o=o+string.len(value)
				break
			end
			
			value=export.is_delimer(text,o,offset_after);
			if value ~= "" then
				output=output..value
				o=o+string.len(value)
				break
			end
		end
	end
	
	return output
end

function export.Vyznam(args)
 	return export.text2wikilinks(args.args[1])
end

return export