모듈:한자

Caeruleum (토론 | 기여)님의 2021년 8월 30일 (월) 11:30 판
설명문서 [편집] [역사] [새로고침]
연습장이나 사용자 문서에서 틀의 사용이나 수정을 연습할 수 있습니다.
분류는 /설명문서에 넣어주세요.

--[[]]
local p = {}
local html = mw.html
local title_ = mw.title
local string_ = require('Module:String')
local getArgs = require('Module:Arguments').getArgs

function p.glyphStyle(frame)
	local args = getArgs(frame)
	local hanja = mw.ustring.sub(args['한자'], -1, -1)
	local lowerCodepoint = string.format("%x", mw.ustring.codepoint(hanja))
	local codepoint = string.upper( lowerCodepoint )
	
	local glyphOrigin = html.create('span'):css('display', 'flex'):addClass('hanja-origin')
	local spanCss = 'display: flex;flex-direction: column;align-items: center;'
	
	local count = 0
	if title_.new('media:'..hanja..'-oracle.svg').exists then count = count + 1 -- 갑골문
		glyphOrigin:tag('span'):cssText(spanCss):wikitext('[[파일:'..hanja..'-oracle.svg|80px]]'):tag('div'):wikitext('갑골문')
	end
	if title_.new('media:'..hanja..'-bronze.svg').exists then count = count + 1 -- 금문
		glyphOrigin:tag('span'):cssText(spanCss):wikitext('[[파일:'..hanja..'-bronze.svg|80px]]'):tag('div'):wikitext('금문')
	end
	if title_.new('media:'..hanja..'-bigseal.svg').exists then count = count + 1 -- 대전
		glyphOrigin:tag('span'):cssText(spanCss):wikitext('[[파일:'..hanja..'-bigseal.svg|80px]]'):tag('div'):wikitext('대전')
	end
	if title_.new('media:'..hanja..'-seal.svg').exists then count = count + 1 -- 소전
		glyphOrigin:tag('span'):cssText(spanCss):wikitext('[[파일:'..hanja..'-seal.svg|80px]]'):tag('div'):wikitext('소전')
	end
	if title_.new('media:U'..codepoint..'.svg').exists then count = count + 1
		local file = '[[파일:U'..codepoint..'.svg|80px]]'
		glyphOrigin:tag('span'):cssText(spanCss):wikitext(file):tag('div'):wikitext('명조')
	elseif title_.new('media:Gw u'..lowerCodepoint..'.svg').exists then count = count + 1
		local file = '[[파일:Gw u'..lowerCodepoint..'.svg|80px]]'
		glyphOrigin:tag('span'):cssText(spanCss):wikitext(file):tag('div'):wikitext('명조')
	elseif title_.new('file:'..hanja..'-명조.svg').exists then count = count + 1
		local file = '[[파일:'..hanja..'-명조.svg|80px]]'
		glyphOrigin:tag('span'):cssText(spanCss):wikitext(file):tag('div'):wikitext('명조')
	end
	local i = 1
	while args[i] ~= nil and i < 13 do
		glyphOrigin:tag('span'):cssText(spanCss):wikitext('[[파일:'..args[i]..'|80px]]'):tag('div'):wikitext(args[i+1])
		i = i + 2
		count = 1
	end
	if count ~= 0 then
		return '== 한자 유래/서체 ==\n'..tostring(glyphOrigin)
	end
end

function p.glyphOrigin(frame)

	local hanja = mw.ustring.sub(frame.args[1], -1, -1)
	
	local root = html.create('span'):css('display', 'flex'):addClass('hanja-origin')
	
	local spanCss = 'display: flex;flex-direction: column;align-items: center;'
	
	if title_.new('media:'..hanja..'-oracle.svg').exists then -- 갑골문
		root:tag('span'):cssText(spanCss):wikitext('[[파일:'..hanja..'-oracle.svg|80px]]'):tag('div'):wikitext('갑골문')
	end
	if title_.new('media:'..hanja..'-bronze.svg').exists then -- 금문
		root:tag('span'):cssText(spanCss):wikitext('[[파일:'..hanja..'-bronze.svg|80px]]'):tag('div'):wikitext('금문')
	end
	if title_.new('media:'..hanja..'-bigseal.svg').exists then -- 대전
		root:tag('span'):cssText(spanCss):wikitext('[[파일:'..hanja..'-bigseal.svg|80px]]'):tag('div'):wikitext('대전')
	end
	if title_.new('media:'..hanja..'-seal.svg').exists then -- 소전
		root:tag('span'):cssText(spanCss):wikitext('[[파일:'..hanja..'-seal.svg|80px]]'):tag('div'):wikitext('소전')
	end
	
	return root
end

function p.strokeOrder(frame)
	local title = frame.args[1]
	local hanja = frame.args[2]
	local style = frame.args[3]
	
	local unicode = string_.tounicode_(hanja)
	
	local file, class
	if title_.new('media:'..hanja..' - '..unicode..' - KanjiVG stroke order.svg').exists then
		class = 'NavFrame collapsed hanja-strokeorder KanjiVG'
		file = '[[파일:'..hanja..' - '..unicode..' - KanjiVG stroke order.svg|200px]]'
	elseif title_.new('media:'..hanja..' - '..unicode..'- KanjiVG stroke order.svg').exists then
		class = 'NavFrame collapsed hanja-strokeorder KanjiVG'
		file = '[[파일:'..hanja..' - '..unicode..'- KanjiVG stroke order.svg|200px]]'
	elseif title_.new('media:'..hanja..'-bw.png').exists then
		class = 'NavFrame collapsed hanja-strokeorder'
		file = '[[파일:'..hanja..'-bw.png]]'
	elseif title_.new('media:'..hanja..'-order.gif').exists then
		class = 'NavFrame collapsed hanja-strokeorder'
		file = '[[파일:'..hanja..'-order.gif|100px]]'
	else
		return title	
	end

	local root = html.create( 'div' ):addClass(class):css('border', 'none'):cssText(style)
		root:tag('div'):addClass('NavHead'):wikitext(title)
		root:tag('div'):addClass('NavContent'):wikitext(file)
	return root
end
return p