편집 요약 없음
편집 요약 없음
 
(사용자 3명의 중간 판 71개는 보이지 않습니다)
1번째 줄: 1번째 줄:
local mw = mw
local ustring = mw.ustring
local ustring = mw.ustring
local getArgs = require('Module:Arguments').getArgs
local p = {}
local p = {}
------------------------- code to char ------------------------------------------
---@param code string string: U+ABCD
function p.tochar(code)
    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


-------------------------  codepoint  ------------------------------------------
-------------------------  codepoint  ------------------------------------------
function p.code(data, base, offset)
---문자 코드를 반환합니다.
     local char
---@param char string
     if type(data) == 'table' then
---@param base string example) 10 : U+1234, r10 : 1234, 16(default) : U+ABCD
        char = getArgs(data)[1] or nil
---@param offset integer 0(default)
    else
---@return string
        char = data
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
     end
    if type(char) == 'number' or type(char) == 'nil' then
 
         return '입력값이 없습니다.'
if offset == nil then
elseif type(offset) ~= 'number' then
         return 'offset is not a number (' .. type(offset) ..')'
     end
     end
     if offset == nil then offset = 0 end
 
     local baseformat, head
     base = base or '16'
    p.codepoint = ustring.codepoint(char)
 
     if base == '10' then
     local codepoint = ustring.codepoint(char) + (offset or 0)
        baseformat = '%d';
 
        head = 'U+'
     if base == 'r10' then
    elseif base == 'r10' then
         return codepoint
         return p.codepoint + offset
    else
        baseformat = '%x';
        head = 'U+'
     end
     end
     return head ..ustring.upper(ustring.format(baseformat, p.codepoint + offset))
 
    local head = 'U+'
    local baseformat = {
        ['10'] = "%d",
        ['16'] = "%x"
    }
 
     return head .. ustring.format(baseformat[base], codepoint):upper()
end
end
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
----------------------  next codepoint  ---------------------------------------
----------------------  next codepoint  ---------------------------------------
---
---입력된 문자의 이후 문자 코드 반환
---@param data table | string table : frame, string : char
---@return string
function p.nextcode(data)
function p.nextcode(data)
    local getArgs = require('Module:Arguments').getArgs --- frame 인수 처리
    local char
     if type(data) == 'table' then
     if type(data) == 'table' then
         char = getArgs(data)[1] or nil
         char = getArgs(data)[1] or nil
36번째 줄: 79번째 줄:
     end
     end
     if char then
     if char then
         return p.code(char, '16', 1)
         return p._code(char, '16', 1)
     else
     else
         return '입력값이 없습니다.'
         return '입력값이 없습니다.'
     end
     end
end
end
----------------------  prev codepoint  ---------------------------------------
----------------------  prev codepoint  ---------------------------------------
---
---입력된 문자의 이전 문자 코드 반환
---@param data table | string table : frame, string : char
---@return string
function p.prevcode(data)
function p.prevcode(data)
    local getArgs = require('Module:Arguments').getArgs --- frame 인수 처리
    local char
     if type(data) == 'table' then
     if type(data) == 'table' then
         char = getArgs(data)[1] or nil
         char = getArgs(data)[1] or nil
49번째 줄: 99번째 줄:
     end
     end
     if char then
     if char then
         return p.code(char, '16', -1)
         return p._code(char, '16', -1)
     else
     else
         return '입력값이 없습니다.'
         return '입력값이 없습니다.'
     end
     end
end
end
----------------------  next char  ---------------------------------------
----------------------  next char  ---------------------------------------
---
---입력된 문자의 이후 문자 반환
---@param data table | string table : frame, string : char
---@return string nextchar
function p.nextchar(data)
function p.nextchar(data)
    local getArgs = require('Module:Arguments').getArgs --- frame 인수 처리
     local char
     local char
     if type(data) == 'table' then
     if type(data) == 'table' then
63번째 줄: 119번째 줄:
     end
     end
     if char then
     if char then
         return ustring.char(p.code(char, 'r10', 1))
         return ustring.char(p._code(char, 'r10', 1))
     else
     else
         return '입력값이 없습니다.'
         return '입력값이 없습니다.'
     end
     end
end
end
----------------------  prev char  ---------------------------------------
----------------------  prev char  ---------------------------------------
---
---입력된 문자의 이전 문자 반환
---@param data table | string table : frame, string : char
---@return string prevchar
function p.prevchar(data)
function p.prevchar(data)
    local getArgs = require('Module:Arguments').getArgs --- frame 인수 처리
     local char
     local char
     if type(data) == 'table' then
     if type(data) == 'table' then
77번째 줄: 139번째 줄:
     end
     end
     if char then
     if char then
         return ustring.char(p.code(char, 'r10', -1))
         return ustring.char(p._code(char, 'r10', -1))
     else
     else
         return '입력값이 없습니다.'
         return '입력값이 없습니다.'
     end
     end
end
end
p.block = require('Module:UnicodeBlock').unicodeBlock
 
----------------------  {{유니코드문자}}  ---------------------------------------
----------------------  {{유니코드문자}}  --------------------------
function p.unicodechar(frame)
---@param frame table
---@return string
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 args = getArgs(frame)
     local class
 
    if args['class'] == 'x' then
     local class = (args['class'] == 'x') and '' or (args['class'] or 'infobox')
    class = ''
 
     else
     local char_current = args[1] or args['기호'] or args['문자'] or nil
    class = 'infobox'
     local char_name = args['이름'] or mw.title.getCurrentTitle().prefixedText
    end
     local eng_name = args['영어이름'] or unicodeBlock(char_current)
     local charname = args['이름'] or mw.title.getCurrentTitle().prefixedText
     local locale = args['lang'] or 'ko'
     local curr = args[1] or args['기호'] or args['문자'] or nil
     local eng = args['영어이름'] or p.block(curr)
     local prefix = args['경로'] or ''
     local prefix = args['경로'] or ''
      
 
     local buildlink, link
     local prev_arrow_icon = '<i class="fas fa-chevron-left uni_char-arrow"></i></span>'
if args['템플릿'] then
     local prev_char = args['이전'] or args['전문자'];
buildlink = require('Module:linkwithtemplate').test
    local prev_linkname = args['전문자이름'] or args['이전이름'] or prev_char
link = function(doc, linkname, template, editintro, arrow)
 
return '<div>' .. buildlink({
    local next_arrow_icon = '<i class="fas fa-chevron-right uni_char-arrow"></i></span>'
            ['템플릿'] = template,
    local next_char = args['이후'] or args['후문자'];
            ['editintro'] = editintro,
    local next_linkname = args['후문자이름'] or args['이후이름'] or next_char
            [1] = doc,
 
            [2] = '<div>' .. linkname .. '<br>' .. arrow .. '</div>'
    local template = args['템플릿']
}) .. '</div>'
    local editintro = args['editintro']
end
 
end
    local prev_link, next_link


     local htmlroot = mw.html.create('table')
     local htmlroot = mw.html.create('table')
    :addClass(class .. ' unicodechar')
        :addClass(class)
    :cssText('margin: 0 auto ;max-width:  ;width:  ;float: right; text-align: center; clear:right')
        :addClass('uni_char')
   
        :cssText('margin: 0 auto; float: right; text-align: center; clear:right')
     local tr, td
 
     if args['이름'] == '없음' then
     local header
         tr = ustring.format('<tr><th colspan="3"><small>%s</small></th></tr>',eng)
     if char_name == '없음' then
         header = ustring.format('<tr><th colspan="3"><small>%s</small></th></tr>', eng_name)
     else
     else
         tr = ustring.format('<tr><th colspan="3"><div>%s</div><small>%s</small></th></tr>',charname, eng)
         header = ustring.format('<tr><th colspan="3"><div>%s</div><small>%s</small></th></tr>', char_name, eng_name)
     end
     end
   
 
     local prev, next
     local function buildlink(article, linkname, arrow, preload, editintro)
     if curr == nil then
        if preload then
         return
            return _buildlink(article, string.format('<div>%s<br>%s</div>', linkname, arrow), preload, editintro)
            '<span class="warning">기호(문자)를 입력하지 않았습니다. |문자 = (문자)</span>'
        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
     else
         local prev_ = args['이전'] or args['전문자'] or nil;
         if char_current:find("[Uu]") then
         local next_ = args['이후'] or args['후문자'] or nil;
            char_current = p.tochar(char_current)
         if prev_ then
        end
        local prevname = args['전문자이름'] or args['이전이름'] or prev_
         --------------------- 이전 문자
prev = ustring.format('[[%s|<div>%s<br>←</div>]]', prev_, prevname)
         if prev_char then
else
            prev_link = buildlink(prev_char, prev_linkname, prev_arrow_icon, template, editintro)
             local prevchar = ustring.char(p.code(curr, 'r10', -1))
            --- 이전 문자 없으면 자동 계산
             local page, linkname
        else
        if ustring.codepoint(prevchar) > 65535 then
             local char = ustring.char(p._code(char_current, 'r10', -1))
                local prevcode = p.code(curr, '16', -1)
             local article = prefix .. (ustring.codepoint(char) > 65535 and p._code(char_current, '16', -1) or char)
                page = prevcode; linkname = prevchar
 
            else
             prev_link = buildlink(article, prev_linkname or char, prev_arrow_icon, template, editintro)
            page = prevchar; linkname = prevchar
        end
             if args['템플릿'] then
                if mw.title.new(page).exists then
                prev = ustring.format('[%s|<div>%s<br>←</div>]', page, linkname)
                else
                prev = link(prefix .. page, linkname, args['템플릿'],args['editintro'], '←')
                end
            else
            prev = ustring.format('[%s|<div>%s<br>→</div>]', page, linkname)
            end
         end
         end
         if next_ then
        ------------------- 다음 문자
        local nextname = args['후문자이름'] or args['이후이름'] or next_
         if next_char then
next = ustring.format('[[%s|<div>%s<br>→</div>]]', next_, nextname)
            next_link = buildlink(next_char, next_linkname, next_arrow_icon, template, editintro)
else
            --- 이전 문자 없으면 자동 계산
local nextchar = ustring.char(p.code(curr, 'r10', 1))
        else
             local page, linkname
            local char = ustring.char(p._code(char_current, 'r10', 1))
        if ustring.codepoint(nextchar) > 65535 then
             local article = prefix .. (ustring.codepoint(char) > 65535 and p._code(char_current, '16', 1) or char)
                local nextcode = p.code(curr, '16', 1)
 
                page = nextcode; linkname = nextchar
             next_link = buildlink(article, next_linkname or char, next_arrow_icon, template, editintro)
             else
            page = nextchar; linkname = nextchar
        end
            if args['템플릿'] then
                if mw.title.new(page).exists then
                next = ustring.format('[%s|<div>%s<br>→</div>]', page, linkname)
                else
                next = link(prefix .. page, linkname, args['템플릿'],args['editintro'], '→')
                end
            else
                next = ustring.format('[[%s|<div>%s<br>→</div>]]', page, linkname)
            end
         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)
    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>
<div style="font-size:80%%; color: gray; ">%s</div></td>
<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