모듈:한자 정보/minimal: 두 판 사이의 차이

편집 요약 없음
편집 요약 없음
84번째 줄: 84번째 줄:


     local hanja_header = ''
     local hanja_header = ''
    local descriptions_List = {};
     -- hanja(漢)
     -- hanja(漢)
     local hanja = args[1]
     local hanja, description = args[1], arg[2]
 
    for i = 2, 4, 2 do
        if args[i] then
            table.insert(descriptions_List, [[<span class='mean'> ]] .. args[i] .. [[</span>]])
        end
        if args[i + 1] then
            table.insert(descriptions_List, [[ <i>]] .. args[i + 1] .. [[</i>]])
        end
    end


     local link = createlink({
     local link = createlink({
105번째 줄: 95번째 줄:


     hanja_info_header:addCharacter(link)
     hanja_info_header:addCharacter(link)
     hanja_info_header:addDescription(table.concat(descriptions_List))
     hanja_info_header:addDescription(description)


     return '<span class="hanja-mean-sound">' .. hanja_info_header:done() .. '</span>'
     return '<span class="hanja-mean-sound">' .. hanja_info_header:done() .. '</span>'

2024년 5월 10일 (금) 03:01 판

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

파리할 [망]

갑옷 [갑]

연습장이나 사용자 문서에서 틀의 사용이나 수정을 연습할 수 있습니다.
분류는 /설명문서에 넣어주세요.

local p = {}
local mw = mw
local createlink = require('Module:linkwithtemplate').test

---return 'U+ABCD'
---@param str string
---@return string
local function tounicode(str)
    return 'U+' .. string.format('%x', mw.ustring.codepoint(str)):upper()
end


local hanja_info_header = {
    html = mw.html.create('p'):addClass('hanja-info-header hanja-mean-sound')
}

hanja_info_header.hanja = hanja_info_header.html:tag('span'):addClass('hanja')
hanja_info_header.description = hanja_info_header.html:tag('span'):addClass('description')

---
---@param char string
function hanja_info_header:addCharacter(char)
    self.hanja:wikitext(char)
end

---
---@param char string
function hanja_info_header:addDescription(char)
    self.description:wikitext(char)
end

function hanja_info_header:done()
    return tostring(self.html:done())
end

---comment
---@param mode string
---@param data table
---@param frame table
---@return string
---@return boolean isStandalone
function p.mean_sound(mode, data, frame)
    local isStandalone;

    if mode == '한자' then
        isStandalone = true

        hanja_info_header.html:addClass('onlyhanja')
        hanja_info_header:addCharacter('[[' .. data.char .. ']]')
    elseif mode == '신자체' then
        isStandalone = true

        hanja_info_header.html:addClass('onlyhanja')
        hanja_info_header:addCharacter(frame:preprocess { text = '{{일본어=|[[' .. data.char .. ']]}}' })
    elseif mode == "간체자" then
        isStandalone = true

        hanja_info_header.html:addClass('onlyhanja')
        hanja_info_header:addCharacter(frame:preprocess { text = '{{중국어=|[[' .. data.char .. ']]}}' })
    end

    if mode == '훈음' then
        isStandalone = false

        hanja_info_header:addCharacter('[[' .. data.char .. ']]')
        hanja_info_header:addDescription(data.mean_sound)
    elseif mode == "중국어" then
        isStandalone = false

        hanja_info_header:addCharacter(frame:preprocess { text = '{{중국어=|[[' .. data.char .. ']]}}' })
        hanja_info_header:addDescription(data.mean_sound)
    else
        isStandalone = false

        hanja_info_header:addCharacter('[[' .. data.char .. ']]')
        hanja_info_header:addDescription(data.mean_sound)
    end

    return hanja_info_header:done(), isStandalone
end

function p.main(frame)
    local args = require('Module:Arguments').getArgs(frame)

    local hanja_header = ''
    -- hanja(漢)
    local hanja, description = args[1], arg[2]

    local link = createlink({
        [1] = '시리즈:리브레_한자사전/' .. (mw.ustring.codepoint(hanja) > 65535 and tounicode(hanja) or hanja),
        [2] = hanja,
        ['템플릿'] = '리브레 위키:템플릿/한자',
        ['editintro'] = '리브레 위키:템플릿/한자/editintro',
    })

    hanja_info_header:addCharacter(link)
    hanja_info_header:addDescription(description)

    return '<span class="hanja-mean-sound">' .. hanja_info_header:done() .. '</span>'
end

return p