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