FANDOM


m
Line 27: Line 27:
 
local header = string.sub(wikitable, 1, rowP[1] - 1)
 
local header = string.sub(wikitable, 1, rowP[1] - 1)
 
local body = string.sub(
 
local body = string.sub(
wikitable, rowPositions[firstRow], rowP[lastRow + 1]
+
wikitable, rowP[firstRow], rowP[lastRow + 1]
 
)
 
)
 
return header .. body .. "}"
 
return header .. body .. "}"

Revision as of 03:26, 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, rowP[firstRow], rowP[lastRow + 1]
        )
    return header .. body .. "}"
end
 
return p
 
--[[Category:Modules]]
Community content is available under CC-BY-SA unless otherwise noted.