이 모듈에 대한 설명문서는 모듈:Timetable/설명문서에서 만들 수 있습니다

local p = {}

-- CSV 데이터를 받아 wikitable 형식으로 변환하는 함수
function p.csv(frame)
    local csv = frame.args[1] or ''
    local lines = {}
    local result = '{| class="timetable" style="border: 2.5px solid var(--text); text-align: right;"\n'

    -- CSV 데이터를 줄 단위로 분리
    for line in csv:gmatch("[^\r\n]+") do
        table.insert(lines, line)
    end

    for i = 1, #lines do
        local row = lines[i]
        local values = {}
        -- 데이터를 쉼표로 분리하여 values 테이블에 저장
        for value in row:gmatch("[^,]+") do
value = value:gsub("%^", 'rowspan="')
value = value:gsub(";", '" |')
value = value:gsub("x", "ELLIPSIS")
value = value:gsub("q", "〃")
value = value:gsub("v", "レ")
value = value:gsub("i", "‖")
value = value:gsub("%.","ENDSPAN")
value = value:gsub("<", 'colspan="')
value = value:gsub("h", 'style="padding-left: 1.06rem; padding-right: 1.06rem; text-align: justify; text-align-last: justify;"')
value = value:gsub("b", '<span style="font-size: 1.2em; font-weight: 700;">')
value = value:gsub("/", "<br/>")
value = value:gsub("ENDSPAN","</span>")
value = value:gsub("ELLIPSIS","...")

            if string.find(value, "|") then
                table.insert(values, value)
            else
                table.insert(values, "|" .. value)
            end
        end

        for j, value in ipairs(values) do
            if j == 1 then
                values[j] = [[style="padding-left: 1.06rem; text-align: justify; text-align-last: justify; border-right: none;"]] .. value
            elseif j == 2 then
                values[j] = 'style="text-align: center; padding-left: 0.2rem; padding-right: 0.2rem; border-left: none; border-right: 1px solid var(--text); margin-left: -1rem;"' .. value
            elseif j == 3 then
                values[j] = [[style="font-family: Monaco, 'Lucida Console', 'Andale Mono', 'Courier New', Courier, monospace; width: calc(0.12rem + 4ch); border-left: 1px solid var(--text);"]] .. value
            else
                values[j] = [[style="font-family: Monaco, 'Lucida Console', 'Andale Mono', 'Courier New', Courier, monospace; width: calc(0.12rem + 4ch);"]] .. value
            end
        end

        for j, value in ipairs(values) do
            if string.find(value, "!!") then
                  table.remove(values, j)
            end
        end

        if i == 1 then
            result = result .. '|- style="border-bottom: 1px solid var(--text); text-align: center !important;"\n| ' .. table.concat(values, " \n| ") .. "\n"
        elseif i == 2 then
            result = result .. '|- style="text-align: center !important;"\n| ' .. table.concat(values, " \n| ") .. "\n"
        elseif i == 3 then
            result = result .. '|- style="border-bottom: 1.7px solid var(--text); text-align: center !important;"\n| ' .. table.concat(values, " \n| ") .. "\n"
        elseif i == 4 then
            result = result .. '|- style="border-bottom: double var(--text);"\n| ' .. table.concat(values, " \n| ") .. "\n"
        else 
            result = result .. "|-\n| " .. table.concat(values, " \n| ") .. "\n"
        end
    end

    result = result .. "|}"
    return result
end

return p