FANDOM

!
21 Pages

local helloworld = {}
local replace = mw.ustring.gsub
local trim = mw.text.trim
local itersplit = mw.text.gsplit
local split = mw.text.split
local match = mw.ustring.match
local itermatch = mw.ustring.gmatch
local find = mw.ustring.find
 
function helloworld.gallery(frame)
	local args = mw.clone(frame:getParent().args)
 
	local caption, colorpair = args['caption'] or '', args['color'] or 'royalblue; white'
 
	colorpair = split(colorpair, '; ?')
 
	local gallery = mw.html.create('gallery')
	gallery
		:attr('caption', caption)
 
		:attr('bordercolor', colorpair[1])
		:attr('captiontextcolor', colorpair[2])
 
		:attr('bordersize', 'none')
 
		:attr('captionposition', 'within')
		:attr('captionalign', 'center')
 
		:attr('widths', '115')
		:attr('position', 'center')
		:attr('spacing', 'small')
		:attr('orientation', 'square')
 
		:attr('navigation', 'true')
		:attr('orientation', 'true')
 
	local files, captions, targets = {}, {}, {}
	local skip_me_i_am_not_a_link = false
	for i = 1, #args do
		local one, two, three = args[i], args[i+1] or '', args[i+2] or ''
 
		if skip_me_i_am_not_a_link == true then
			skip_me_i_am_not_a_link = false
		elseif skip_me_i_am_not_a_link == false then
			if find(one, '%.%w%w%w$') then
				table.insert(files, trim(one))
				table.insert(captions, trim(two))
 
				if find(three, '%.%w%w%w$') then
					table.insert(targets, '')
					skip_me_i_am_not_a_link = true
				else
					table.insert(targets, trim(three))
				end
			end
		end
	end
 
	for i = 1, #files do
		if not find(captions[i], '%[%[') and targets[i] ~= '' then
			captions[i] = '[[' .. targets[i] .. '|' .. captions[i] .. ']]'
		end
 
		gallery:wikitext('\n' .. files[i] .. '|' .. captions[i] .. '|link=' .. targets[i])
	end
 
	gallery = tostring(gallery)
	gallery = frame:preprocess(gallery)
 
	return gallery
end
 
function helloworld.lim(frame)
	local text = mw.text.unstripNoWiki(frame.args[1])
 
	text = trim(text)
 
	text = replace(text, '`', ' || ')
	text = replace(text, '\n', '\n|-\n| ')
 
	text = replace(text, '(%a)2', '%1́')
	text = replace(text, '(%a)3', '%1̀')
	text = replace(text, '(%a)5', '%1̂')
	text = replace(text, '(%a)6', '%1̃')
	text = replace(text, '(%a)7', '%1̄')
	text = replace(text, '(%a)8', '%1̍')
 
	text = replace(text, 'UU', 'ṳ')
	text = replace(text, 'NN', 'ⁿ')
 
	text = replace(text, '叫', '呌')
	text = replace(text, '攜', '携')
 
	text = replace(text, '他', '伊')
	text = replace(text, '你', '爾')
 
	text = mw.ustring.toNFC(text)
 
	return frame:preprocess('<pre><nowiki>' .. text .. '\n\n</nowiki></pre>')
end
 
function helloworld.akusento(frame)
	local text = mw.text.unstripNoWiki(frame.args[1])
 
	text = trim(text)
 
	text = '{{rh|000|{{bold|000—000}}|000}}\n{{rule}}\n{{multicol|line=1px solid black}}\n' .. text .. '\n{{multicol-end}}\n{{nop}}'
 
	text = replace(text, '\n\n', '\n{{multicol-break}}\n')
 
	text = replace(text, '\n([^\n ]+) ', '\n{{bold|%1}} ')
	text = replace(text, '「', '{{ol|')
	text = replace(text, '」', '}}')
	text = replace(text, '([^\n]+)', '%1\n')
 
	text = trim(text)
 
	return frame:preprocess('<pre><nowiki>' .. text .. '\n\n</nowiki></pre>')
end
 
function helloworld.gen(frame)
	local start = tonumber(frame.args[1]) or 1
	local roof = tonumber(frame.args[2]) or 50
	local increment = tonumber(frame.args[3]) or 1
 
	local prepend = frame.args['^'] or ''
	local append = frame.args['$'] or ''
 
	local numbers = {}
 
	local i = start
 
	while not (i > roof) do
		table.insert(numbers, ' ' .. prepend .. i .. append)
		i = i + increment
	end
 
	return table.concat(numbers, '\n')
end
 
function helloworld.aa(frame)
	local text = mw.text.unstripNoWiki(frame.args[1])
 
	text = trim(text)
 
	local out = {}
 
	local function rom(text)
		text = replace(text, '/(.+)/', '<i>%1</i>')
		return replace(text, '([%[%]~])', {['[']='̆', [']']='̆', ['~'] = 'ʼ'})
	end
 
	local lastditto = {}
	lastditto['en'] = '{{ditto|????????|do.}}'
	lastditto['zh'] = '丨'
	lastditto['rom'] = '{{ditto|????????}}'
 
	local function ditto(text, lang)
		return replace(text, '=', lastditto[lang])
	end
 
	for line in itersplit(text, '\n') do
		if find(line, '`') then
			line = split(line, '`')
 
			if #line == 3 then
				line[1] = ditto(line[1], 'en')
				line[2] = ditto(line[2], 'zh')
				line[3] = ditto(line[3], 'rom')
 
				line[3] = rom(line[3])
 
				line[1] = '! ' .. line[1] .. '\n'
				line[2] = '| ' .. line[2] .. ' || '
				line[3] = line[3] .. '\n|-\n'
			elseif #line == 4 then
				line[2] = ditto(line[2], 'en')
				line[3] = ditto(line[3], 'zh')
				line[4] = ditto(line[4], 'rom')
 
				line[4] = rom(line[4])
 
				line[1] = '! ' .. line[1] .. ' || '
				line[2] = line[2] .. '\n'
				line[3] = '| ' .. line[3] .. ' || '
				line[4] = line[4] .. '\n|-\n'
			end
 
			table.insert(out, table.concat(line, ''))
		elseif line ~= '' then
			line = '|+ ' .. line .. '\n|-\n'
			table.insert(out, line)
		elseif line == '' then
			table.insert(out, '\n\n')
		else
			table.insert(out, line)
		end
	end
 
	text = table.concat(out, '')
 
	text = mw.ustring.toNFC(text)
 
	return frame:preprocess('<pre><nowiki>' .. text .. '\n\n</nowiki></pre>')
end
 
return helloworld