모듈:Unicode: 두 판 사이의 차이
보이기
편집 요약 없음 |
편집 요약 없음 |
||
| 4번째 줄: | 4번째 줄: | ||
------------------------- codepoint ------------------------------------------ | ------------------------- codepoint ------------------------------------------ | ||
function p.code( data, base, offset ) | function p.code(data, base, offset) | ||
local char | |||
if type(data) == 'table' then | |||
char = getArgs(data)[1] or nil | |||
else | |||
char = data | |||
end | |||
if type(char) == 'number' or type(char) == 'nil' then | |||
return '입력값이 없습니다.' | |||
end | |||
if offset == nil then offset = 0 end | |||
local baseformat, head | |||
p.codepoint = ustring.codepoint(char) | |||
if base == '10' then | |||
baseformat = '%d'; | |||
head = 'U+' | |||
elseif base == 'r10' then | |||
return p.codepoint + offset | |||
else | |||
baseformat = '%x'; | |||
head = 'U+' | |||
end | |||
return head ..ustring.upper(ustring.format(baseformat, p.codepoint + offset)) | |||
end | end | ||
---------------------- next codepoint --------------------------------------- | ---------------------- next codepoint --------------------------------------- | ||
function p.nextcode( data ) | 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 | end | ||
---------------------- prev codepoint --------------------------------------- | ---------------------- prev codepoint --------------------------------------- | ||
function p.prevcode( data ) | 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 | end | ||
---------------------- next char --------------------------------------- | ---------------------- next char --------------------------------------- | ||
function p.nextchar( data ) | 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, 'r10', 1)) | |||
else | |||
return '입력값이 없습니다.' | |||
end | |||
end | end | ||
---------------------- prev char --------------------------------------- | ---------------------- prev char --------------------------------------- | ||
function p.prevchar( data ) | 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, 'r10', -1)) | |||
else | |||
return '입력값이 없습니다.' | |||
end | |||
end | end | ||
p.block = require('Module:UnicodeBlock').unicodeBlock | p.block = require('Module:UnicodeBlock').unicodeBlock | ||
---------------------- {{유니코드문자}} --------------------------------------- | ---------------------- {{유니코드문자}} --------------------------------------- | ||
function p.unicodechar( frame ) | function p.unicodechar(frame) | ||
local args = getArgs(frame) | |||
local class | |||
if args['class'] == 'x' then | |||
class = '' | |||
else | |||
class = 'infobox' | |||
end | |||
local charname = args['이름'] or mw.title.getCurrentTitle().prefixedText | |||
local curr = args[1] or args['기호'] or args['문자'] or nil | |||
local eng = args['영어이름'] or p.block(curr) | |||
local prefix = args['경로'] or '' | |||
local buildlink = require('Module:linkwithtemplate').test | |||
local link = function(doc, linkname, template, editintro, arrow) | |||
return '<div>' .. buildlink({ | |||
['템플릿'] = template, | |||
['editintro'] = editintro, | |||
[1] = doc, | |||
[2] = '<div>' .. linkname .. '<br>' .. arrow .. '</div>' | |||
}) .. '</div>' | |||
end | |||
local htmlroot = mw.html.create('table') | |||
:addClass(class .. ' unicodechar') | |||
:cssText('margin: 0 auto ;max-width: ;width: ;float: right; text-align: center; clear:right') | |||
local tr, td | |||
if args['이름'] == '없음' then | |||
tr = ustring.format('<tr><th colspan="3"><small>%s</small></th></tr>',eng) | |||
else | |||
tr = ustring.format('<tr><th colspan="3"><div>%s</div><small>%s</small></th></tr>',charname, eng) | |||
end | |||
local prev, next | |||
if curr == nil then | |||
return | |||
'<span class="warning">기호(문자)를 입력하지 않았습니다. |문자 = (문자)</span>' | |||
else | |||
local prev_ = args['이전'] or args['전문자'] or nil; | |||
local next_ = args['이후'] or args['후문자'] or nil; | |||
if ustring.codepoint(curr) > 65535 then | |||
if prev_ then | |||
prev = ustring.format('[[%s|<div>%s<br>←</div>]]', prev_, prev_) | |||
else | |||
local prevcode = p.code(curr, '16', -1) | |||
local prevchar = ustring.char(p.code(curr, 'r10', -1)) | |||
if args['템플릿'] then | |||
prev = link(prefix .. prevcode, prevchar, args['템플릿'],args['editintro'], '←') | |||
else | |||
prev = ustring.format('[[%s|<div>%s<br>←</div>]]',prevcode, prevchar) | |||
end | |||
end | |||
if next_ then | |||
next = ustring.format('[[%s|<div>%s<br>→</div>]]', next_, next_) | |||
else | |||
local nextcode = p.code(curr, '16', 1); | |||
local nextchar = ustring.char(p.code(curr, 'r10', 1)) | |||
if args['템플릿'] then | |||
next = link(prefix .. nextcode, nextchar, args['템플릿'],args['editintro'], '→') | |||
else | |||
next = ustring.format('[[%s|<div>%s<br>→</div>]]',nextcode, nextchar) | |||
end | |||
end | |||
else | |||
if prev_ then | |||
prev = ustring.format('[[%s|<div>%s<br>←</div>]]', prev_, prev_) | |||
else | |||
local prevchar = ustring.char(p.code(curr, 'r10', -1)) | |||
if args['템플릿'] then | |||
prev = link(prefix .. prevchar, prevchar, args['템플릿'],args['editintro'], '←') | |||
else | |||
prev = ustring.format('[[%s|<div>%s<br>←</div>]]',prevchar, prevchar) | |||
end | |||
end | |||
if next_ then | |||
next = ustring.format('[[%s|<div>%s<br>→</div>]]', next_, next_) | |||
else | |||
local nextchar = ustring.char(p.code(curr, 'r10', 1)) | |||
if args['템플릿'] then | |||
next = link(prefix .. nextchar, nextchar, args['템플릿'],args['editintro'], '→') | |||
else | |||
next = ustring.format('[[%s|<div>%s<br>→</div>]]',nextchar, nextchar) | |||
end | |||
end | |||
end | |||
end | |||
tr = tr..ustring.format( | |||
[[<td style="width: 110px;font-size:1.2em;">%s</td> | |||
<td style="width: 80px"> | |||
<div style="font-size: 1.8em;line-height: 1.4em;"><b>%s</b></div> | |||
<div style="font-size:80%%; color: gray; line-height: 2.2em;">%s</div> | |||
</td> | |||
<td style="width: 110px;font-size:1.2em;">%s</td>]], prev, curr, p.code(curr), next) | |||
return htmlroot:node(tr) | |||
end | end | ||
return p | return p | ||
2022년 1월 9일 (일) 13:20 판
{{#css: .template-documentation {
clear: both; margin: 1em 0 0 0; padding: 1em
} /* 아래 상자 */ .mbox-text {
clear: both; background-color: #e8ffe8;
}
.template-documentation-template-data .mw-templatedata-doc-desc {
display: none;
}
}}
모듈:Unicode을 이용합니다.
스크립트 오류: 함수 "uni_char"가 존재하지 않습니다.
{{유니코드문자|[}}
스크립트 오류: 함수 "uni_char"가 존재하지 않습니다.
{{유니코드문자|이름=왼쪽 대괄호|[}}
아래는 가능한 모든 변수들을 나열한 것입니다.
스크립트 오류: 함수 "uni_char"가 존재하지 않습니다.
위 설명은 모듈:Unicode/설명문서의 내용을 가져와 보여주고 있습니다.
연습장이나 사용자 문서에서 틀의 사용이나 수정을 연습할 수 있습니다.
local ustring = mw.ustring
local getArgs = require('Module:Arguments').getArgs
local p = {}
------------------------- codepoint ------------------------------------------
function p.code(data, base, offset)
local char
if type(data) == 'table' then
char = getArgs(data)[1] or nil
else
char = data
end
if type(char) == 'number' or type(char) == 'nil' then
return '입력값이 없습니다.'
end
if offset == nil then offset = 0 end
local baseformat, head
p.codepoint = ustring.codepoint(char)
if base == '10' then
baseformat = '%d';
head = 'U+'
elseif base == 'r10' then
return p.codepoint + offset
else
baseformat = '%x';
head = 'U+'
end
return head ..ustring.upper(ustring.format(baseformat, p.codepoint + offset))
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, 'r10', 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, 'r10', -1))
else
return '입력값이 없습니다.'
end
end
p.block = require('Module:UnicodeBlock').unicodeBlock
---------------------- {{유니코드문자}} ---------------------------------------
function p.unicodechar(frame)
local args = getArgs(frame)
local class
if args['class'] == 'x' then
class = ''
else
class = 'infobox'
end
local charname = args['이름'] or mw.title.getCurrentTitle().prefixedText
local curr = args[1] or args['기호'] or args['문자'] or nil
local eng = args['영어이름'] or p.block(curr)
local prefix = args['경로'] or ''
local buildlink = require('Module:linkwithtemplate').test
local link = function(doc, linkname, template, editintro, arrow)
return '<div>' .. buildlink({
['템플릿'] = template,
['editintro'] = editintro,
[1] = doc,
[2] = '<div>' .. linkname .. '<br>' .. arrow .. '</div>'
}) .. '</div>'
end
local htmlroot = mw.html.create('table')
:addClass(class .. ' unicodechar')
:cssText('margin: 0 auto ;max-width: ;width: ;float: right; text-align: center; clear:right')
local tr, td
if args['이름'] == '없음' then
tr = ustring.format('<tr><th colspan="3"><small>%s</small></th></tr>',eng)
else
tr = ustring.format('<tr><th colspan="3"><div>%s</div><small>%s</small></th></tr>',charname, eng)
end
local prev, next
if curr == nil then
return
'<span class="warning">기호(문자)를 입력하지 않았습니다. |문자 = (문자)</span>'
else
local prev_ = args['이전'] or args['전문자'] or nil;
local next_ = args['이후'] or args['후문자'] or nil;
if ustring.codepoint(curr) > 65535 then
if prev_ then
prev = ustring.format('[[%s|<div>%s<br>←</div>]]', prev_, prev_)
else
local prevcode = p.code(curr, '16', -1)
local prevchar = ustring.char(p.code(curr, 'r10', -1))
if args['템플릿'] then
prev = link(prefix .. prevcode, prevchar, args['템플릿'],args['editintro'], '←')
else
prev = ustring.format('[[%s|<div>%s<br>←</div>]]',prevcode, prevchar)
end
end
if next_ then
next = ustring.format('[[%s|<div>%s<br>→</div>]]', next_, next_)
else
local nextcode = p.code(curr, '16', 1);
local nextchar = ustring.char(p.code(curr, 'r10', 1))
if args['템플릿'] then
next = link(prefix .. nextcode, nextchar, args['템플릿'],args['editintro'], '→')
else
next = ustring.format('[[%s|<div>%s<br>→</div>]]',nextcode, nextchar)
end
end
else
if prev_ then
prev = ustring.format('[[%s|<div>%s<br>←</div>]]', prev_, prev_)
else
local prevchar = ustring.char(p.code(curr, 'r10', -1))
if args['템플릿'] then
prev = link(prefix .. prevchar, prevchar, args['템플릿'],args['editintro'], '←')
else
prev = ustring.format('[[%s|<div>%s<br>←</div>]]',prevchar, prevchar)
end
end
if next_ then
next = ustring.format('[[%s|<div>%s<br>→</div>]]', next_, next_)
else
local nextchar = ustring.char(p.code(curr, 'r10', 1))
if args['템플릿'] then
next = link(prefix .. nextchar, nextchar, args['템플릿'],args['editintro'], '→')
else
next = ustring.format('[[%s|<div>%s<br>→</div>]]',nextchar, nextchar)
end
end
end
end
tr = tr..ustring.format(
[[<td style="width: 110px;font-size:1.2em;">%s</td>
<td style="width: 80px">
<div style="font-size: 1.8em;line-height: 1.4em;"><b>%s</b></div>
<div style="font-size:80%%; color: gray; line-height: 2.2em;">%s</div>
</td>
<td style="width: 110px;font-size:1.2em;">%s</td>]], prev, curr, p.code(curr), next)
return htmlroot:node(tr)
end
return p