편집 요약 없음
편집 요약 없음
태그: 되돌려진 기여
21번째 줄: 21번째 줄:
             value = value:gsub("v", "レ")
             value = value:gsub("v", "レ")
             value = value:gsub("i", "‖")
             value = value:gsub("i", "‖")
             value = value:gsub("R", 'colspan="2"')
             value = value:gsub("R", 'colspan="2" |')
             value = value:gsub("D", 'rowspan="2"')
             value = value:gsub("D", 'rowspan="2" |')
             value = value:gsub("L", 'class="removetd"')
             value = value:gsub("L", 'class="removetd" |')
             value = value:gsub("U", 'class="removetd"')
             value = value:gsub("U", 'class="removetd" |')
             table.insert(values, "|" .. value)
             table.insert(values, "|" .. value)
         end
         end

2025년 8월 9일 (토) 00:42 판

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

local p = {}

-- CSV 데이터를 받아 wikitable 형식으로 변환하는 함수
function p.csv(frame)
    local csv = frame.args[1] or ''
    local lines = {}
    local result = '{| class="wikitable timetable" style="border: 2px solid var(--text);"\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("x", "…")
            value = value:gsub("/", "<br/>")
            value = value:gsub("v", "レ")
            value = value:gsub("i", "‖")
            value = value:gsub("R", 'colspan="2" |')
            value = value:gsub("D", 'rowspan="2" |')
            value = value:gsub("L", 'class="removetd" |')
            value = value:gsub("U", 'class="removetd" |')
            table.insert(values, "|" .. value)
        end

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

        if i == 4 then
            result = result .. '|- style="border-bottom: double var(--text);"\n| ' .. table.concat(values, " || ") .. "\n"
        else 
            result = result .. "|-\n| " .. table.concat(values, " || ") .. "\n"
        end
    end

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

return p