편집 요약 없음 |
편집 요약 없음 |
||
| (같은 사용자의 중간 판 3개는 보이지 않습니다) | |||
| 6번째 줄: | 6번째 줄: | ||
---@param code string string: U+ABCD | ---@param code string string: U+ABCD | ||
function p.tochar(code) | function p.tochar(code) | ||
return ustring.char(tonumber(code:gsub(" ", ""):gsub("[Uu][+]", "0x"), 16)) | |||
end | end | ||
| 14번째 줄: | 14번째 줄: | ||
---@return string | ---@return string | ||
function p.tounicode(frame) | function p.tounicode(frame) | ||
return 'U+' .. string.format('%x', ustring.codepoint(frame.args[1])):upper() | |||
end | end | ||
------------------------- codepoint ------------------------------------------ | ------------------------- codepoint ------------------------------------------ | ||
---문자 코드를 반환합니다. | ---문자 코드를 반환합니다. | ||
---@param | ---@param char string | ||
---@param base string example) 10 : U+1234, r10 : 1234, 16( | ---@param base string example) 10 : U+1234, r10 : 1234, 16(default) : U+ABCD | ||
---@param offset integer | ---@param offset integer 0(default) | ||
---@return string | ---@return string | ||
function p._code(char, base, offset) | |||
if char == nil then | |||
return 'char is nil' | |||
end | |||
if type(char) ~= 'string' then | |||
return 'char is not a string (' .. type(char) ..')' | |||
end | |||
if offset == nil then | |||
elseif type(offset) ~= 'number' then | |||
return 'offset is not a number (' .. type(offset) ..')' | |||
end | |||
base = base or '16' | |||
local codepoint = ustring.codepoint(char) + (offset or 0) | |||
if base == 'r10' then | |||
return codepoint | |||
end | |||
local head = 'U+' | |||
local baseformat = { | |||
['10'] = "%d", | |||
['16'] = "%x" | |||
} | |||
return head .. ustring.format(baseformat[base], codepoint):upper() | |||
end | |||
function p.code(data, base, offset) | function p.code(data, base, offset) | ||
local getArgs = require('Module:Arguments').getArgs --- frame 인수 처리 | |||
local char = getArgs(data)[1] or nil | |||
return p._code(char, base, offset) | |||
end | end | ||
---------------------- next codepoint --------------------------------------- | ---------------------- next codepoint --------------------------------------- | ||
--- | --- | ||
| 54번째 줄: | 71번째 줄: | ||
---@return string | ---@return string | ||
function p.nextcode(data) | function p.nextcode(data) | ||
local getArgs = require('Module:Arguments').getArgs --- frame 인수 처리 | |||
local char | |||
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 --------------------------------------- | ||
--- | --- | ||
| 73번째 줄: | 91번째 줄: | ||
---@return string | ---@return string | ||
function p.prevcode(data) | function p.prevcode(data) | ||
local getArgs = require('Module:Arguments').getArgs --- frame 인수 처리 | |||
local char | |||
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 --------------------------------------- | ||
--- | --- | ||
| 92번째 줄: | 111번째 줄: | ||
---@return string nextchar | ---@return string nextchar | ||
function p.nextchar(data) | function p.nextchar(data) | ||
local getArgs = require('Module:Arguments').getArgs --- frame 인수 처리 | |||
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 --------------------------------------- | ||
--- | --- | ||
| 111번째 줄: | 131번째 줄: | ||
---@return string prevchar | ---@return string prevchar | ||
function p.prevchar(data) | function p.prevchar(data) | ||
local getArgs = require('Module:Arguments').getArgs --- frame 인수 처리 | |||
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 | ||
---------------------- {{유니코드문자}} -------------------------- | ---------------------- {{유니코드문자}} -------------------------- | ||
---@param frame table | ---@param frame table | ||
---@return string | ---@return string | ||
function p. | function p.uni_char(frame) | ||
local unicodeBlock = require('Module:UnicodeBlock').unicodeBlock | |||
local _buildlink = require('Module:linkwithtemplate').makelink | |||
local getArgs = require('Module:Arguments').getArgs --- frame 인수 처리 | |||
---@type table | |||
local args = getArgs(frame) | |||
local class = (args['class'] == 'x') and '' or (args['class'] or 'infobox') | |||
local char_current = args[1] or args['기호'] or args['문자'] or nil | |||
local char_name = args['이름'] or mw.title.getCurrentTitle().prefixedText | |||
local eng_name = args['영어이름'] or unicodeBlock(char_current) | |||
local locale = args['lang'] or 'ko' | |||
local prefix = args['경로'] or '' | |||
local prev_arrow_icon = '<i class="fas fa-chevron-left uni_char-arrow"></i></span>' | |||
local prev_char = args['이전'] or args['전문자']; | |||
local prev_linkname = args['전문자이름'] or args['이전이름'] or prev_char | |||
local next_arrow_icon = '<i class="fas fa-chevron-right uni_char-arrow"></i></span>' | |||
local | local next_char = args['이후'] or args['후문자']; | ||
local next_linkname = args['후문자이름'] or args['이후이름'] or next_char | |||
local template = args['템플릿'] | |||
local editintro = args['editintro'] | |||
local prev_link, next_link | |||
local htmlroot = mw.html.create('table') | |||
:addClass(class) | |||
:addClass('uni_char') | |||
:cssText('margin: 0 auto; float: right; text-align: center; clear:right') | |||
local header | |||
if char_name == '없음' then | |||
header = ustring.format('<tr><th colspan="3"><small>%s</small></th></tr>', eng_name) | |||
else | |||
header = ustring.format('<tr><th colspan="3"><div>%s</div><small>%s</small></th></tr>', char_name, eng_name) | |||
end | |||
local function buildlink(article, linkname, arrow, preload, editintro) | |||
if preload then | if preload then | ||
return | return _buildlink(article, string.format('<div>%s<br>%s</div>', linkname, arrow), preload, editintro) | ||
else | else | ||
return ustring.format('[[%s|<div>%s<br>%s</div>]]', article, linkname, arrow or '') | return ustring.format('[[%s|<div>%s<br>%s</div>]]', article, linkname, arrow or '') | ||
end | end | ||
end | end | ||
if char_current == nil then | |||
return '<span class="warning">기호 인수가 없습니다.</span>' | |||
else | else | ||
if | if char_current:find("[Uu]") then | ||
char_current = p.tochar(char_current) | |||
end | end | ||
--------------------- 이전 문자 | --------------------- 이전 문자 | ||
if prev_char then | |||
prev_link = buildlink(prev_char, prev_linkname, prev_arrow_icon, template, editintro) | |||
--- 이전 문자 없으면 자동 계산 | |||
else | |||
local char = ustring.char(p._code(char_current, 'r10', -1)) | |||
local article = prefix .. (ustring.codepoint(char) > 65535 and p._code(char_current, '16', -1) or char) | |||
prev_link = buildlink(article, prev_linkname or char, prev_arrow_icon, template, editintro) | |||
end | |||
------------------- 다음 문자 | ------------------- 다음 문자 | ||
if next_char then | |||
next_link = buildlink(next_char, next_linkname, next_arrow_icon, template, editintro) | |||
--- 이전 문자 없으면 자동 계산 | |||
else | |||
local char = ustring.char(p._code(char_current, 'r10', 1)) | |||
local article = prefix .. (ustring.codepoint(char) > 65535 and p._code(char_current, '16', 1) or char) | |||
next_link = buildlink(article, next_linkname or char, next_arrow_icon, template, editintro) | |||
end | |||
end | |||
local t = {} | |||
local format = | |||
[[<td class='uni_char-prev' style="width: 7em;font-size:1.2em;" lang="%s">%s</td> | |||
<td class='uni_char-char' style="width: 6em"><div style="font-size: 1.8em;line-height: 1.4em;"><b lang="%s">%s</b></div> | |||
[[<td class=' | |||
<td class=' | |||
<div style="font-size:80%%; color: gray; ">%s</div></td> | <div style="font-size:80%%; color: gray; ">%s</div></td> | ||
<td class=' | <td class='uni_char-next' style="width: 7em;font-size:1.2em;" lang="%s">%s</td>]] | ||
if args['순서반전'] then | |||
header = ustring.format(format .. "%s", locale, prev_link, locale, char_current, p._code(char_current), locale, | |||
next_link, header) | |||
else | |||
header = ustring.format("%s" .. format, header, locale, prev_link, locale, char_current, p._code(char_current), | |||
locale, next_link) | |||
end | |||
return tostring(htmlroot:node(header)) | |||
end | end | ||
return p | return p | ||