편집 요약 없음
태그: 되돌려진 기여
편집 요약 없음
태그: 되돌려진 기여
28번째 줄: 28번째 줄:
     end
     end


     -- 테이블의 각 셀에서 스타일을 추가하고 병합 규칙 적용
     -- 테이블을 돌면서 병합 규칙 처리
    local merged_cells = {}
   
    -- 병합된 셀을 추적할 변수
     for i = 1, #table_data do
     for i = 1, #table_data do
         result = result .. "|-\n"
         result = result .. "|-\n"
        for j, value in ipairs(table_data[i]) do
            -- 각 열에 스타일 적용
            if j == 1 then
                table_data[i][j] = 'style="text-align: justify; text-align-last: justify; border-right: none;" | ' .. value
            elseif j == 2 then
                table_data[i][j] = [[style="text-align: justify; text-align-last: justify; border-left: none; border-right: 1px solid var(--text);" | ]] .. value
            else
                table_data[i][j] = [[style="text-align: center; font-family: Monaco, 'Lucida Console', 'Andale Mono', 'Courier New', Courier, monospace;" | ]] .. value
            end
        end
        -- 병합 규칙 처리
         for j = 1, #table_data[i] do
         for j = 1, #table_data[i] do
             local value = table_data[i][j]
             local value = table_data[i][j]
             local merge_flag = ""
             local merge_flag = ""


            -- 'L', 'R', 'U', 'D' 처리
             if value == "L" and j > 1 then
             if value == "L" and j > 1 then
                 merge_flag = ' colspan="2"'
                 merge_flag = ' colspan="2"'
                 table_data[i][j] = nil  -- 'L' 셀은 삭제
                 table_data[i][j] = nil  -- L 셀은 삭제
             elseif value == "R" and j < #table_data[i] then
             elseif value == "R" and j < #table_data[i] then
                 merge_flag = ' colspan="2"'
                 merge_flag = ' colspan="2"'
                 table_data[i][j + 1] = nil  -- 'R' 셀은 삭제하고 오른쪽 병합
                 table_data[i][j + 1] = nil  -- R 셀은 삭제하고 오른쪽 병합
             elseif value == "U" and i > 1 then
             elseif value == "U" and i > 1 then
                 merge_flag = ' rowspan="2"'
                 merge_flag = ' rowspan="2"'
                 table_data[i][j] = nil  -- 'U' 셀은 삭제
                 table_data[i][j] = nil  -- U 셀은 삭제
             elseif value == "D" and i < #table_data then
             elseif value == "D" and i < #table_data then
                 merge_flag = ' rowspan="2"'
                 merge_flag = ' rowspan="2"'
                 table_data[i + 1][j] = nil  -- 'D' 셀은 삭제하고 아래쪽 병합
                 table_data[i + 1][j] = nil  -- D 셀은 삭제하고 아래쪽 병합
             end
             end


             -- 병합된 출력
             -- 스타일을 적용하고 병합된 셀을 출력
             if table_data[i][j] then
             if table_data[i][j] then
                 result = result .. "| " .. table_data[i][j] .. merge_flag .. "\n"
                -- 스타일을 적용
                local cell_value = table_data[i][j]
                if j == 1 then
                    cell_value = 'style="text-align: justify; text-align-last: justify; border-right: none;" | ' .. cell_value
                elseif j == 2 then
                    cell_value = 'style="text-align: justify; text-align-last: justify; border-left: none; border-right: 1px solid var(--text);" | ' .. cell_value
                else
                    cell_value = 'style="text-align: center; font-family: Monaco, \'Lucida Console\', \'Andale Mono\', \'Courier New\', Courier, monospace;" | ' .. cell_value
                end
                 result = result .. "| " .. cell_value .. merge_flag .. "\n"
             else
             else
                -- 병합된 셀에는 내용이 없으므로 빈 셀을 표시
                 result = result .. "| " .. merge_flag .. "\n"
                 result = result .. "| " .. merge_flag .. "\n"
             end
             end

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

이 모듈에 대한 설명문서는 모듈: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 데이터를 줄 단위로 분리하여 lines 테이블에 저장
    for line in csv:gmatch("[^\r\n]+") do
        table.insert(lines, line)
    end

    -- 테이블 데이터 준비
    local table_data = {}
    for i = 1, #lines do
        local row = lines[i]
        local values = {}
        -- 데이터를 쉼표로 분리하여 values 테이블에 저장
        for value in row:gmatch("[^,]+") do
            value = value:gsub("x", "…")  -- 'x'를 ellipsis로 변환
            value = value:gsub("/", "<br/>")  -- '/'를 줄 바꿈으로 변환
            value = value:gsub("v", "レ")  -- 'v'를 일본어 'レ'로 변환
            value = value:gsub("i", "‖")  -- 'i'를 기호로 변환
            table.insert(values, value)
        end
        table.insert(table_data, values)
    end

    -- 테이블을 돌면서 병합 규칙 처리
    local merged_cells = {}
    
    -- 병합된 셀을 추적할 변수
    for i = 1, #table_data do
        result = result .. "|-\n"
        for j = 1, #table_data[i] do
            local value = table_data[i][j]
            local merge_flag = ""

            -- 'L', 'R', 'U', 'D' 처리
            if value == "L" and j > 1 then
                merge_flag = ' colspan="2"'
                table_data[i][j] = nil  -- L 셀은 삭제
            elseif value == "R" and j < #table_data[i] then
                merge_flag = ' colspan="2"'
                table_data[i][j + 1] = nil  -- R 셀은 삭제하고 오른쪽 병합
            elseif value == "U" and i > 1 then
                merge_flag = ' rowspan="2"'
                table_data[i][j] = nil  -- U 셀은 삭제
            elseif value == "D" and i < #table_data then
                merge_flag = ' rowspan="2"'
                table_data[i + 1][j] = nil  -- D 셀은 삭제하고 아래쪽 병합
            end

            -- 스타일을 적용하고 병합된 셀을 출력
            if table_data[i][j] then
                -- 스타일을 적용
                local cell_value = table_data[i][j]
                if j == 1 then
                    cell_value = 'style="text-align: justify; text-align-last: justify; border-right: none;" | ' .. cell_value
                elseif j == 2 then
                    cell_value = 'style="text-align: justify; text-align-last: justify; border-left: none; border-right: 1px solid var(--text);" | ' .. cell_value
                else
                    cell_value = 'style="text-align: center; font-family: Monaco, \'Lucida Console\', \'Andale Mono\', \'Courier New\', Courier, monospace;" | ' .. cell_value
                end
                result = result .. "| " .. cell_value .. merge_flag .. "\n"
            else
                -- 병합된 셀에는 내용이 없으므로 빈 셀을 표시
                result = result .. "| " .. merge_flag .. "\n"
            end
        end
    end

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

return p