FANDOM


-- Table constructor
 
local p = {}
 
local function rowPositions(wikitable)
    local positions = {}
    local index = 1
 
    for pos = 1, string.len(wikitable) - 1 do
        if string.sub(wikitable, pos, pos + 1) == "|-" then
            positions[index] = pos
            index = index + 1
        end
    end
 
    positions[index] = string.len(wikitable) - 1
 
    return {positions, index - 1}
end
 
local function fetchRows(wikitable, firstRow, lastRow)
    local rowP = rowPositions(wikitable)[1]
    return string.sub(wikitable, rowP[firstRow], rowP[lastRow + 1])
end
 
local function fetchOneRow(wikitable, row)
    return fetchRows(wikitable, row, row)
end
 
function p.partialTable(frame)
    local wikitable = frame.args[1]
    local rowP = rowPositions(wikitable)[1]
    local length = rowPositions(wikitable)[2]
    local firstRow = math.max(frame.args[2], 1) or 1
    local lastRow = math.min(frame.args[3], length) or length
    local header = string.sub(wikitable, 1, rowP[1] - 1)
    local body = fetchRows(wikitable, firstRow, lastRow)
    return header .. body .. "}"
end
 
return p
 
--[[Category:Modules]]
Community content is available under CC-BY-SA unless otherwise noted.