편집 요약 없음
편집 요약 없음
 
(사용자 2명의 중간 판 37개는 보이지 않습니다)
1번째 줄: 1번째 줄:
local mw = mw
local mw = mw
local ustring = mw.ustring
local ustring = mw.ustring
local getArgs = require('Module:Arguments').getArgs --- frame 변수 처리
local p = {}
local p = {}


7번째 줄: 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))
    return ustring.char(tonumber(code:gsub(" ", ""):gsub("[Uu][+]", "0x"), 16))
end
 
------------------------- codepoint (frame) ------------------------------------------
---return 'U+ABCD'
---@param frame table
---@return string
function p.tounicode(frame)
    return 'U+' .. string.format('%x', ustring.codepoint(frame.args[1])):upper()
end
end


-------------------------  codepoint  ------------------------------------------
-------------------------  codepoint  ------------------------------------------
---
---문자 코드를 반환합니다.
---문자 코드를 반환합니다.
---@param data table | string table : frame, string : char
---@param char string
---@param base string example) 10 : U+1234, r10 : 1234, 16(normal) : U+ABCD
---@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 char
    local getArgs = require('Module:Arguments').getArgs --- frame 인수 처리
if type(data) == 'table' then
 
char = getArgs(data)[1] or nil
    local char = getArgs(data)[1] or nil
else
 
char = data
    return p._code(char, base, offset)
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  ---------------------------------------
---
---
47번째 줄: 71번째 줄:
---@return string
---@return string
function p.nextcode(data)
function p.nextcode(data)
local char
    local getArgs = require('Module:Arguments').getArgs --- frame 인수 처리
if type(data) == 'table' then
    local char
char = getArgs(data)[1] or nil
    if type(data) == 'table' then
else
        char = getArgs(data)[1] or nil
char = data or nil
    else
end
        char = data or nil
if char then
    end
return p.code(char, '16', 1)
    if char then
else
        return p._code(char, '16', 1)
return '입력값이 없습니다.'
    else
end
        return '입력값이 없습니다.'
    end
end
end
----------------------  prev codepoint  ---------------------------------------
----------------------  prev codepoint  ---------------------------------------
---
---
65번째 줄: 91번째 줄:
---@return string
---@return string
function p.prevcode(data)
function p.prevcode(data)
local char
    local getArgs = require('Module:Arguments').getArgs --- frame 인수 처리
if type(data) == 'table' then
    local char
char = getArgs(data)[1] or nil
    if type(data) == 'table' then
else
        char = getArgs(data)[1] or nil
char = data or nil
    else
end
        char = data or nil
if char then
    end
return p.code(char, '16', -1)
    if char then
else
        return p._code(char, '16', -1)
return '입력값이 없습니다.'
    else
end
        return '입력값이 없습니다.'
    end
end
end
----------------------  next char  ---------------------------------------
----------------------  next char  ---------------------------------------
---
---
83번째 줄: 111번째 줄:
---@return string nextchar
---@return string nextchar
function p.nextchar(data)
function p.nextchar(data)
local char
    local getArgs = require('Module:Arguments').getArgs --- frame 인수 처리
if type(data) == 'table' then
    local char
char = getArgs(data)[1] or nil
    if type(data) == 'table' then
else
        char = getArgs(data)[1] or nil
char = data or nil
    else
end
        char = data or nil
if char then
    end
return ustring.char(p.code(char, 'r10', 1))
    if char then
else
        return ustring.char(p._code(char, 'r10', 1))
return '입력값이 없습니다.'
    else
end
        return '입력값이 없습니다.'
    end
end
end
----------------------  prev char  ---------------------------------------
----------------------  prev char  ---------------------------------------
---
---
101번째 줄: 131번째 줄:
---@return string prevchar
---@return string prevchar
function p.prevchar(data)
function p.prevchar(data)
local char
    local getArgs = require('Module:Arguments').getArgs --- frame 인수 처리
if type(data) == 'table' then
    local char
char = getArgs(data)[1] or nil
    if type(data) == 'table' then
else
        char = getArgs(data)[1] or nil
char = data or nil
    else
end
        char = data or nil
if char then
    end
return ustring.char(p.code(char, 'r10', -1))
    if char then
else
        return ustring.char(p._code(char, 'r10', -1))
return '입력값이 없습니다.'
    else
end
        return '입력값이 없습니다.'
    end
end
end
p.block = require('Module:UnicodeBlock').unicodeBlock
 
----------------------  {{유니코드문자}}  --------------------------
----------------------  {{유니코드문자}}  --------------------------
---@param frame table
---@param frame table
---@return string
---@return string
function p.unicodechar(frame)
function p.uni_char(frame)
---@type table
    local unicodeBlock = require('Module:UnicodeBlock').unicodeBlock
---@
    local _buildlink = require('Module:linkwithtemplate').makelink
local args = getArgs(frame)
    local getArgs = require('Module:Arguments').getArgs --- frame 인수 처리
local class
 
if args['class'] == 'x' then
    ---@type table
class = ''
    local args = getArgs(frame)
elseif args['class'] == nil then
 
class = 'infobox'
    local class = (args['class'] == 'x') and '' or (args['class'] or 'infobox')
else
 
class = args['class']
    local char_current = args[1] or args['기호'] or args['문자'] or nil
end
    local char_name = args['이름'] or mw.title.getCurrentTitle().prefixedText
local charname = args['이름'] or mw.title.getCurrentTitle().prefixedText
    local eng_name = args['영어이름'] or unicodeBlock(char_current)
local curr = args[1] or args['기호'] or args['문자'] or nil
    local locale = args['lang'] or 'ko'
local eng = args['영어이름'] or p.block(curr)
    local prefix = args['경로'] or ''
local lang = args['lang'] or 'ko'
 
local prefix = args['경로'] or ''
    local prev_arrow_icon = '<i class="fas fa-chevron-left uni_char-arrow"></i></span>'
local arrowPrev = '<span class="unicodechar-arrow"><i class="fas fa-long-arrow-left"></i></span>'
    local prev_char = args['이전'] or args['전문자'];
local arrowNext = '<span class="unicodechar-arrow"><i class="fas fa-long-arrow-right"></i></span>'
    local prev_linkname = args['전문자이름'] or args['이전이름'] or prev_char
 
local link
    local next_arrow_icon = '<i class="fas fa-chevron-right uni_char-arrow"></i></span>'
if args['템플릿'] then
    local next_char = args['이후'] or args['후문자'];
local buildlink = require('Module:linkwithtemplate').test
    local next_linkname = args['후문자이름'] or args['이후이름'] or next_char
link = function(doc, linkname, template, editintro, arrow)
 
return buildlink({
    local template = args['템플릿']
['템플릿'] = template,
    local editintro = args['editintro']
['editintro'] = editintro,
 
[1] = doc,
    local prev_link, next_link
[2] = '<div>'..linkname..'<br>'..arrow..'</div>'
 
})
    local htmlroot = mw.html.create('table')
end
        :addClass(class)
end
        :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
            return _buildlink(article, string.format('<div>%s<br>%s</div>', linkname, arrow), preload, editintro)
        else
            return ustring.format('[[%s|<div>%s<br>%s</div>]]', article, linkname, arrow or '')
        end
    end
 
    if char_current == nil then
        return '<span class="warning">기호 인수가 없습니다.</span>'
    else
        if char_current:find("[Uu]") then
            char_current = p.tochar(char_current)
        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)


local htmlroot = mw.html.create('table')
            next_link = buildlink(article, next_linkname or char, next_arrow_icon, template, editintro)
:addClass(class)
        end
:addClass('unicodechar')
    end
:cssText('margin: 0 auto ;max-width:  ;width: ;float: right; text-align: center; clear:right')
 
    local t = {}
local tr, td
 
if args['이름'] == '없음' then
    local format =
tr = ustring.format('<tr><th colspan="3"><small>%s</small></th></tr>',eng)
    [[<td class='uni_char-prev' style="width: 7em;font-size:1.2em;" lang="%s">%s</td>
else
<td class='uni_char-char' style="width: 6em"><div style="font-size: 1.8em;line-height: 1.4em;"><b lang="%s">%s</b></div>
tr = ustring.format('<tr><th colspan="3"><div>%s</div><small>%s</small></th></tr>',charname, eng)
<div style="font-size:80%%; color: gray; ">%s</div></td>
end
<td class='uni_char-next' style="width: 7em;font-size:1.2em;" lang="%s">%s</td>]]
 
local prev, next
    if args['순서반전'] then
if curr == nil then
        header = ustring.format(format .. "%s", locale, prev_link, locale, char_current, p._code(char_current), locale,
return
            next_link, header)
'<span class="warning">기호(문자)를 입력하지 않았습니다. |문자 = (문자)</span>'
    else
end
        header = ustring.format("%s" .. format, header, locale, prev_link, locale, char_current, p._code(char_current),
if curr:find("[Uu]") then
            locale, next_link)
curr = p.tochar(curr)
    end
end
    return tostring(htmlroot:node(header))
if curr then
function internalLink( pagename, text, arrow)
arrow = arrow or ''
return ustring.format('[[%s|<div>%s<br>%s</div>]]', pagename, text, arrow)
end
local prev_ = args['이전'] or args['전문자'] or nil;
local next_ = args['이후'] or args['후문자'] or nil;
if prev_ then
local prevname = args['전문자이름'] or args['이전이름'] or prev_
prev = internalLink(prev_, prevname, arrowPrev)
else
local prevchar = ustring.char(p.code(curr, 'r10', -1))
local page, linkname
if ustring.codepoint(prevchar) > 65535 then
local prevcode = p.code(curr, '16', -1)
page = prevcode; linkname = prevchar
else
page = prevchar; linkname = prevchar
end
if args['템플릿'] then
if mw.title.new(page).exists then
prev = internalLink( page, linkname, arrowPrev)
else
prev = link(prefix .. page, linkname, args['템플릿'],args['editintro'], arrowPrev)
end
else
prev = internalLink( page, linkname, arrowPrev)
end
end
if next_ then
local nextname = args['후문자이름'] or args['이후이름'] or next_
next = internalLink( next_, nextname, arrowNext)
else
local nextchar = ustring.char(p.code(curr, 'r10', 1))
local page, linkname
if ustring.codepoint(nextchar) > 65535 then
local nextcode = p.code(curr, '16', 1)
page = nextcode; linkname = nextchar
else
page = nextchar; linkname = nextchar
end
if args['템플릿'] then
if mw.title.new(page).exists then
next = internalLink( page, linkname, arrowNext)
else
next = link(prefix .. page, linkname, args['템플릿'],args['editintro'], arrowNext)
end
else
next = internalLink( page, linkname, arrowNext)
end
end
end
if args['순서반전'] then
tr = ustring.format([[
<td class='unicodechar-prev' style="width: 7em;font-size:1.2em;" lang="%s">%s</td>
<td class='unicodechar-char' style="width: 6em"><div style="font-size: 1.8em;line-height: 1.4em;"><b lang="%s">%s</b></div>
<span style="font-size:80%%; color: gray; line-height: 2.2em;">%s</span></td>
<td class='unicodechar-next' style="width: 7em;font-size:1.2em;" lang="%s">%s</td>]], lang, prev, lang, curr, p.code(curr), lang, next)..tr
else
tr = tr..ustring.format([[
<td class='unicodechar-prev' style="width: 7em;font-size:1.2em;" lang="%s">%s</td>
<td class='unicodechar-char' style="width: 6em"><div style="font-size: 1.8em;line-height: 1.4em;"><b lang="%s">%s</b></div>
<span style="font-size:80%%; color: gray; line-height: 2.2em;">%s</span></td>
<td class='unicodechar-next' style="width: 7em;font-size:1.2em;" lang="%s">%s</td>]], lang, prev, lang, curr, p.code(curr), lang, next)
end
return htmlroot:node(tr)
end
end


return p
return p