Module:Wikt

From Ekatra Foundation
Jump to navigation Jump to search

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

require('strict')

local p = {} --p stands for package

local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')
local error_message = require('Module:Error')['error']

function p._wikt(args)
	local link = args.link or args[1]
	if not link then
		return error_message({message = '[[Module:Wikt]] error: no link provided'})
	end
	
	local text = args.text or args[2] or link
	local anchor = args.anchor or args[3]
	local gray = yesno(args.gray or false)
	
	if gray then
		text = tostring(mw.html.create('span'):css({['color'] = 'dimgray'}):wikitext(text))
	end
	if anchor then
		anchor = mw.uri.anchorEncode(anchor)
	end
	
	return '[[' .. mw.title.makeTitle('', link, anchor, 'wikt').fullText .. '|' .. text .. ']]'
end

function p.wikt(frame)
	return p._wikt(getArgs(frame))
end

return p