Jump to content

Module:RemoveMiddleColumn

From Untitled Monster Game
Revision as of 14:43, 30 December 2025 by imported>Ziebster

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 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
   else
    table.insert(result,line)
   end
  else
   table.insert(result,line)
  end
 end
 return table.concat(result,"\n")
end

return p