모듈:UnicodeBlock: 두 판 사이의 차이

편집 요약 없음
편집 요약 없음
79번째 줄: 79번째 줄:
local eng = args['영어이름'] or ''
local eng = args['영어이름'] or ''
local root = mw.html.create('table'):addClass('wikitable'):cssText('margin: 0 0.4em;max-width:100%;width: 21em;float: right; text-align: center; clear:both')
local root = mw.html.create('table'):addClass('infobox'):cssText('margin: 0 0.4em;max-width:100%;width: 21em;float: right; text-align: center; clear:both')
local tr, td
local tr, td



2021년 12월 22일 (수) 20:26 판

설명문서 [편집] [역사] [새로고침]

문자를 입력하면 유니코드 블록 위치가 출력됩니다.

스크립트 오류: 함수 "unicodeBlock"가 존재하지 않습니다.

스크립트 오류: 함수 "unicodeBlock"가 존재하지 않습니다.

스크립트 오류: 함수 "_"가 존재하지 않습니다.

스크립트 오류: 함수 "_"가 존재하지 않습니다.

{{#invoke:unicodeBlock|unicodeBlock|1}}
{{#invoke:unicodeBlock|unicodeBlock|Z}}
{{#invoke:unicodeBlock|_|한}}
{{#invoke:unicodeBlock|_|Σ}}
연습장이나 사용자 문서에서 틀의 사용이나 수정을 연습할 수 있습니다.
분류는 /설명문서에 넣어주세요.

local ustring = mw.ustring
local getArgs = require('Module:Arguments').getArgs
local p = {}

-------------------------  codepoint  ------------------------------------------
function p.code( data )
	if type(data) == 'table' then
		data = getArgs(frame)[1] or nil
	elseif type(data) == 'string' then
		return p.code_(char)
	else
		return '입력값이 없습니다.'
	end
end
function p.code_( char, base, offset )
	if type(char) == 'string' then
		if offset == nil then offset = 0 end
		local baseformat, head
		if base == '10' then
			baseformat = '%d'; head = 'U+'
		elseif base == 'x16' then
			baseformat = '%x'; head = 0
			return ustring.codepoint(char) + offset
		else
			baseformat = '%x'; head = 'U+'
		end
		return head..ustring.upper(ustring.format(baseformat, ustring.codepoint(char) + offset))
	else
		return 0
	end
end
----------------------  next codepoint  ---------------------------------------
function p.nextcode( data )
	if type(data) == 'table' then	char = getArgs(data)[1] or nil
	else	char = data or nil end	if char then
		return p.code_(char, '16', 1)
	else
		return '입력값이 없습니다.'
	end
end
----------------------  prev codepoint  ---------------------------------------
function p.prevcode( data )
	if type(data) == 'table' then	char = getArgs(data)[1] or nil
	else	char = data or nil end
	if char then
		return p.code_(char, '16', -1)
	else
		return '입력값이 없습니다.'
	end
end
----------------------  next char  ---------------------------------------
function p.nextchar( data )
	local char
	if type(data) == 'table' then	char = getArgs(data)[1] or nil
	else	char = data or nil end
	if char then
		return ustring.char(p.code_(char, 'x16', 1))
	else
		return '입력값이 없습니다.'
	end
end
----------------------  prev char  ---------------------------------------
function p.prevchar( data )
	local char
	if type(data) == 'table' then	char = getArgs(data)[1] or nil
	else	char = data or nil end
	if char then
		return ustring.char(p.code_(char, 'x16', -1))
	else
		return '입력값이 없습니다.'
	end
end
----------------------  {틀:유니코드문자}  ---------------------------------------
function p.unicodechar( frame )
	local args = getArgs(frame)
	local charname
	if args['이름'] == nil then charname = mw.title.getCurrentTitle().prefixedText
	else charname = args['이름'] end
	local eng = args['영어이름'] or ''
	
	local root = mw.html.create('table'):addClass('infobox'):cssText('margin: 0 0.4em;max-width:100%;width: 21em;float: right; text-align: center; clear:both')
	local tr, td

	if args['이름'] ~= '없음' then
		tr = ustring.format('<tr><th colspan="3"><div>%s</div><small>%s</small></th></tr>', charname, eng)
	else
		tr = ustring.format('<tr><th colspan="3"><small>%s</small></th></tr>', eng)
	end
	root:node(tr)

    tr = mw.html.create('tr')
    local curr = args['기호'] or args['문자'] or ' '
    local prev, next
    if curr == ' ' then
		return '<span class="warning">기호(문자)를 입력하지 않았습니다. |기호 = (기호)</span>'
	else
    	if ustring.codepoint(curr) > 65535 then
    		prev = args['이전'] or args['전문자'] or '[['..p.prevcode(curr)..'|'..p.prevchar(curr)..']]'
    		next = args['이후'] or args['후문자'] or '[['..p.nextcode(curr)..'|'..p.nextchar(curr)..']]'
    	else
    		prev = args['이전'] or args['전문자'] or '[['..p.prevchar(curr)..']]'
    		next = args['이후'] or args['후문자'] or '[['..p.nextchar(curr)..']]'
    	end
    end
	td = ustring.format('<td style="width: 38%%;font-size:1.2em;"><div>%s</div>←</td>', prev)
	tr:node(td)

	td = ustring.format('<td style="width:4em"><div style="font-size: 1.8em;line-height: 1.2em;"><b>%s</b></div><small><span style="color: gray;">%s</span></small></td>', curr, p.code_(curr))
	tr:node(td)
    
	td = ustring.format('<td style="width: 38%%;font-size:1.2em;"><div>%s</div>→</td>', next)
	tr:node(td)

    root:node(tr)
	
	return tostring(root)
end

return p