모듈:Large category TOC

local p = {}
local azupper = mw.text.split('ABCDEFGHIJKLMNOPQRSTUVWXYZ',)
local azlower = mw.text.split('abcdefghijklmnopqrstuvwxyz',)
local hangulmain = mw.text.split('가까나다따라마바빠사싸아자짜차카타파하',)
local hangul1 = mw.text.split('가개갸걔거게겨계고과괘괴교구궈궤규그긔기',)
local hangul2 = mw.text.split('까깨꺄꺠꺼께껴꼐꼬꽈꽤꾀꾜꾸꿔꿰뀨끄끠끼',)
local hangul3 = mw.text.split('나내냐냬너네녀녜노놔놰뇌뇨누눠눼뉴느늬니',)
local hangul4 = mw.text.split('다대댜댸더데뎌뎨도돠돼되됴두둬뒈듀드듸디',)
local hangul5 = mw.text.split('따때땨떄떠떼뗘뗴또똬뙈뙤뚀뚜뚸뛔뜌뜨띄띠',)
local hangul6 = mw.text.split('라래랴럐러레려례로롸뢔뢰료루뤄뤠류르릐리',)
local hangul7 = mw.text.split('마매먀먜머메며몌모뫄뫠뫼묘무뭐뭬뮤므믜미',)
local hangul8 = mw.text.split('바배뱌뱨버베벼볘보봐봬뵈뵤부붜붸뷰브븨비',)
local hangul9 = mw.text.split('빠빼뺘뺴뻐뻬뼈뼤뽀뽜뽸뾔뾰뿌뿨쀄쀼쁘쁴삐',)
local hangul10 = mw.text.split('사새샤섀서세셔셰소솨쇄쇠쇼수숴쉐슈스싀시',)
local hangul11 = mw.text.split('싸쌔쌰썌써쎄쎠쎼쏘쏴쐐쐬쑈쑤쒀쒜쓔쓰씌씨',)
local hangul12 = mw.text.split('아애야얘어에여예오와왜외요우워웨유으의이',)
local hangul13 = mw.text.split('자재쟈쟤저제져졔조좌좨죄죠주줘줴쥬즈즤지',)
local hangul14 = mw.text.split('짜째쨔쨰쩌쩨쪄쪠쪼쫘쫴쬐쬬쭈쭤쮀쮸쯔쯰찌',)
local hangul15 = mw.text.split('차채챠챼처체쳐쳬초촤쵀최쵸추춰췌츄츠츼치',)
local hangul16 = mw.text.split('카캐캬컈커케켜켸코콰쾌쾨쿄쿠쿼퀘큐크킈키',)
local hangul17 = mw.text.split('타태탸턔터테텨톄토톼퇘퇴툐투퉈퉤튜트틔티',)
local hangul18 = mw.text.split('파패퍄퍠퍼페펴폐포퐈퐤푀표푸풔풰퓨프픠피',)
local hangul19 = mw.text.split('하해햐햬허헤혀혜호화홰회효후훠훼휴흐희히',)
local aejot = mw.text.split('aejot',)
function p.scrollable(frame)
	return main('scrollable')
end
function p.collapsible(frame)
	return main('collapsible')
end
function p.aejot(frame)
	return main('aejot')
end
function main(toc_type)
	-- It should be much faster to only process these once, and just re use them as variables
	local pageurl = mw.title.getCurrentTitle():fullUrl()
	local toc = mw.message.new('Toc'):plain()
	
	-- Highest level div
	local toc_frame = mw.html.create('div')
				:addClass('large-cat-toc')
				:addClass('plainlinks')
				:addClass('toc')
				-- :attr('id','toc')
	-- Contains "Content: 처음 0-9 A - Z"
	local header = toc_frame:tag('div')
		:attr('id', 'toctitle')
		:attr('class', 'toctitle')
	
	-- Contains all the rest
	local body_wrapper
	local body = toc_frame:tag('div')
		:addClass('large-cat-toc-body')
		
	local jumpy_collapse = mw.html.create('div')
		:addClass('large-cat-toc-jumpy-title')
	
	if toc_type == 'collapsible' then
		toc_frame:addClass('mw-collapsible mw-collapsed')
		body:addClass('mw-collapsible-content')
	elseif toc_type == 'scrollable' then
		toc_frame:addClass('large-cat-toc-scroll')
	end
	
	local header_content = {,toc,':',
						' ',pageurl,' 처음',
						' ',pageurl,'?from=0 0–9'}
	
	for _, v in ipairs(azupper) do
		table.insert(header_content,string.format(' %s?from=%s %s',pageurl,v,v))
	end
	for _, v in ipairs(hangulmain) do
		table.insert(header_content,string.format(' %s?from=%s %s',pageurl,v,v))
	end
	
	if toc_type == 'collapsible' then
		jumpy_collapse:wikitext(table.concat(header_content))
		header:node(jumpy_collapse)
	else
		header:wikitext(table.concat(header_content))
	end
	
	local body_content = {}
	
	if toc_type == 'collapsible' then
		table.insert(body_content,'# ')
		body_wrapper = body:tag('code')
						:css('background','White')
	else
		table.insert(body_content,..pageurl..'?from=* * # ')
		body_wrapper = body:tag('span')
	end
	
	for i=0,9 do
		table.insert(body_content,string.format(' %s?from=%s %s',pageurl,i,i))
	end
	
	local function atoz(letter)
		local azlist = {}
		local letterlist
		if toc_type == 'aejot' then
			letterlist = aejot
		else
			letterlist = azlower
		end
				
		if toc_type == 'aejot' or toc_type == 'scrollable' then
			table.insert(azlist,' • '..letter..)
		else
			table.insert(azlist,' '..letter..)
		end
			
		for _, v in ipairs(letterlist) do
			table.insert(azlist,string.format(' %s?from=%s%s %s%s ',pageurl,letter,v,letter,v))
		end
		return table.concat(azlist)
	end
	local function makehangul(idx, letter)
		local hangullist = {}
		local hangulitems = {}
		if toc_type == 'aejot' or toc_type == 'scrollable' then
			table.insert(hangullist,' • '..letter..' ')
		else
			table.insert(hangullist,..letter..' ')
		end
		if idx == 1 then hangulitems = hangul1
		elseif idx == 2 then hangulitems = hangul2
		elseif idx == 3 then hangulitems = hangul3
		elseif idx == 4 then hangulitems = hangul4
		elseif idx == 5 then hangulitems = hangul5
		elseif idx == 6 then hangulitems = hangul6
		elseif idx == 7 then hangulitems = hangul7
		elseif idx == 8 then hangulitems = hangul8
		elseif idx == 9 then hangulitems = hangul9
		elseif idx == 10 then hangulitems = hangul10
		elseif idx == 11 then hangulitems = hangul11
		elseif idx == 12 then hangulitems = hangul12
		elseif idx == 13 then hangulitems = hangul13
		elseif idx == 14 then hangulitems = hangul14
		elseif idx == 15 then hangulitems = hangul15
		elseif idx == 16 then hangulitems = hangul16
		elseif idx == 17 then hangulitems = hangul17
		elseif idx == 18 then hangulitems = hangul18
		elseif idx == 19 then hangulitems = hangul19
		end
		for _, v in ipairs(hangulitems) do
			table.insert(hangullist,string.format(' %s?from=%s %s ',pageurl,v,v))
		end
		return table.concat(hangullist)
	end
	for _, v in ipairs(azupper) do
		table.insert(body_content,atoz(v))
	end
	for i, v in ipairs(hangulmain) do
		table.insert(body_content,makehangul(i, v))
	end
	body_wrapper:wikitext(table.concat(body_content))
	
	return '__NOTOC__\n' .. mw.getCurrentFrame():extensionTag{
		name = 'templatestyles', args = { src = 'Module:Large category TOC/styles.css' }
	} .. tostring(toc_frame)
end
return p