FANDOM


Line 16: Line 16:
 
positions[index] = string.len(wikitable) - 1
 
positions[index] = string.len(wikitable) - 1
   
return positions
+
return {positions, index - 1}
 
end
 
end
   
 
function p.partial(frame)
 
function p.partial(frame)
 
local wikitable = frame.args[1]
 
local wikitable = frame.args[1]
local rows = table.getn(rowPositions(wikitable)) - 1
+
local rowP = rowPositions(wikitable)[1]
  +
local length = rowPositions(wikitable)[2]
 
local firstRow = math.max(frame.args[2], 1) or 1
 
local firstRow = math.max(frame.args[2], 1) or 1
local lastRow = math.min(frame.args[3], rows) or rows
+
local lastRow = math.min(frame.args[3], length) or length
local header = string.sub(wikitable, 1, rowPositions[1] - 1)
+
local header = string.sub(wikitable, 1, rowP[1] - 1)
 
local body = string.sub(
 
local body = string.sub(
wikitable, rowPositions[firstRow], rowPositions[lastRow + 1]
+
wikitable, rowPositions[firstRow], rowP[lastRow + 1]
 
)
 
)
 
return header .. body .. "}"
 
return header .. body .. "}"

Revision as of 03:22, February 9, 2020

-- 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
 
function p.partial(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 = string.sub(
        wikitable, rowPositions[firstRow], rowP[lastRow + 1]
        )
    return header .. body .. "}"
end
 
return p
 
--[[Category:Modules]]
Community content is available under CC-BY-SA unless otherwise noted.