편집 요약 없음
태그: 되돌려진 기여
편집 요약 없음
태그: 수동 되돌리기
7번째 줄: 7번째 줄:
     local result = '{| class="wikitable timetable" style="border: 2px solid var(--text);"\n'
     local result = '{| class="wikitable timetable" style="border: 2px solid var(--text);"\n'


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


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


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


            -- 스타일을 적용하고 병합된 셀을 출력
        if i == 4 then
            if table_data[i][j] then
            result = result .. '|- style="border-bottom: double var(--text);"\n| ' .. table.concat(values, " || ") .. "\n"
                -- 스타일을 적용
        else  
                local cell_value = table_data[i][j]
            result = result .. "|-\n| " .. table.concat(values, " || ") .. "\n"
                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
     end
     end

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

이 모듈에 대한 설명문서는 모듈: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", "‖")
            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