Jump to content

Module:RemoveMiddleColumn: Difference between revisions

From Untitled Monster Game
imported>Ziebster
No edit summary
imported>Ziebster
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p={}
local p = {}


function p.slim(frame)
function p.slim(frame)
local text=frame.args[1]or""
    local text = frame.args[1] or ""
if text==""then return""end
    if text == "" then return "" end
local lines={}
    local lines = {}
for line in text:gmatch("([^\n])\n?")do
    for line in text:gmatch("([^\n]*)\n?") do
  table.insert(lines,line)
        table.insert(lines, line)
end
local result={}
local col_count=0
local in_table=false
local is_header=false
for _,line in ipairs(lines)do
  local trimmed=line:match("^%s(.-)%s*$")or""
  if trimmed:match("^<section")or trimmed:match("^</section")then
  table.insert(result,line)
  elseif trimmed:match("^%{%|")then
  in_table=true
  is_header=true
  col_count=0
  table.insert(result,line)
  elseif trimmed:match("^|%}")then
  in_table=false
  is_header=false
  col_count=0
  table.insert(result,line)
  elseif in_table then
  if trimmed:match("^|%-")then
    is_header=false
    col_count=0
    table.insert(result,line)
  elseif(is_header and trimmed:match("^!"))or(not is_header and trimmed:match("^|"))then
    col_count=col_count+1
    if col_count~=2 then
    table.insert(result,line)
     end
     end
  else
    local result = {}
     table.insert(result,line)
    local i = 1
  end
     while i <= #lines do
  else
        local trimmed = lines[i]:match("^%s*(.-)%s*$") or ""
  table.insert(result,line)
        if trimmed:match("^<section") or trimmed:match("^</section") then
  end
            table.insert(result, lines[i])
end
        elseif trimmed:match("^%{%|") then
return table.concat(result,"\n")
            table.insert(result, lines[i])
        elseif trimmed:match("^|%}") then
            table.insert(result, lines[i])
        elseif trimmed:match("^|%-") then
            table.insert(result, lines[i])
        elseif trimmed:match("^!") then
            local headers = {}
            while i <= #lines and lines[i]:match("^%s*!") do
                table.insert(headers, lines[i])
                i = i + 1
            end
            i = i - 1
            if #headers == 3 then
                table.insert(result, headers[1])
                table.insert(result, headers[3])
            end
        elseif trimmed:match("^|") and not trimmed:match("^|%-") and not trimmed:match("^|%}") then
            local cells = {}
            while i <= #lines and lines[i]:match("^%s*|") and not lines[i]:match("^%s*|%-") and not lines[i]:match("^%s*|%}") do
                table.insert(cells, lines[i])
                i = i + 1
            end
            i = i - 1
            if #cells == 3 then
                table.insert(result, cells[1])
                table.insert(result, cells[3])
            end
        else
            table.insert(result, lines[i])
        end
        i = i + 1
    end
    return table.concat(result, "\n")
end
end


return p
return p

Latest revision as of 14:53, 30 December 2025

Example Usage:

{{Device Disambiguation|Example}}

local p = {}

function p.slim(frame)
    local text = frame.args[1] or ""
    if text == "" then return "" end
    local lines = {}
    for line in text:gmatch("([^\n]*)\n?") do
        table.insert(lines, line)
    end
    local result = {}
    local i = 1
    while i <= #lines do
        local trimmed = lines[i]:match("^%s*(.-)%s*$") or ""
        if trimmed:match("^<section") or trimmed:match("^</section") then
            table.insert(result, lines[i])
        elseif trimmed:match("^%{%|") then
            table.insert(result, lines[i])
        elseif trimmed:match("^|%}") then
            table.insert(result, lines[i])
        elseif trimmed:match("^|%-") then
            table.insert(result, lines[i])
        elseif trimmed:match("^!") then
            local headers = {}
            while i <= #lines and lines[i]:match("^%s*!") do
                table.insert(headers, lines[i])
                i = i + 1
            end
            i = i - 1
            if #headers == 3 then
                table.insert(result, headers[1])
                table.insert(result, headers[3])
            end
        elseif trimmed:match("^|") and not trimmed:match("^|%-") and not trimmed:match("^|%}") then
            local cells = {}
            while i <= #lines and lines[i]:match("^%s*|") and not lines[i]:match("^%s*|%-") and not lines[i]:match("^%s*|%}") do
                table.insert(cells, lines[i])
                i = i + 1
            end
            i = i - 1
            if #cells == 3 then
                table.insert(result, cells[1])
                table.insert(result, cells[3])
            end
        else
            table.insert(result, lines[i])
        end
        i = i + 1
    end
    return table.concat(result, "\n")
end

return p