Jump to content

Module:RemoveMiddleColumn: Difference between revisions

From Untitled Monster Game
imported>Ziebster
Created page with "local p={} function p.slim(f) local t=f.args[1]or"" if t==""then return""end local l={} for s in t:gmatch("([^\n]*)\n?")do table.insert(l,s)end local r={} for _,s in ipairs(l)do local u=s:match("^%s*(.-)%s*$") if u:match("^%{%|")or u:match("^|%}")then table.insert(r,s) elseif u:match("^!")then local h={} local i=0 for v in u:gmatch("!%s*([^!|]+)")do i=i+1;if i~=2 then table.insert(h,"!"..v:gsub("%s+$",""))end end if#h>0 then table.insert(r," "..t..."
 
imported>Ziebster
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p={}
local p = {}


function p.slim(f)
function p.slim(frame)
local t=f.args[1]or""
    local text = frame.args[1] or ""
if t==""then return""end
    if text == "" then return "" end
local l={}
    local lines = {}
for s in t:gmatch("([^\n]*)\n?")do table.insert(l,s)end
    for line in text:gmatch("([^\n]*)\n?") do
local r={}
        table.insert(lines, line)
for _,s in ipairs(l)do
    end
  local u=s:match("^%s*(.-)%s*$")
    local result = {}
  if u:match("^%{%|")or u:match("^|%}")then table.insert(r,s)
    local i = 1
  elseif u:match("^!")then
    while i <= #lines do
  local h={}
        local trimmed = lines[i]:match("^%s*(.-)%s*$") or ""
  local i=0
        if trimmed:match("^<section") or trimmed:match("^</section") then
  for v in u:gmatch("!%s*([^!|]+)")do i=i+1;if i~=2 then table.insert(h,"!"..v:gsub("%s+$",""))end end
            table.insert(result, lines[i])
  if#h>0 then table.insert(r," "..table.concat(h," !! "))end
        elseif trimmed:match("^%{%|") then
  elseif u:match("^|%-")then table.insert(r,"|-")
            table.insert(result, lines[i])
  elseif u:match("^|")then
        elseif trimmed:match("^|%}") then
  local c={}
            table.insert(result, lines[i])
  local i=0
        elseif trimmed:match("^|%-") then
  for v in u:gmatch("|%s*([^|]+)")do i=i+1;if i~=2 then table.insert(c,"|"..v:gsub("%s+$",""))end end
            table.insert(result, lines[i])
  if#c>=2 then
        elseif trimmed:match("^!") then
    local b=table.concat(c," || ")
            local headers = {}
    b=b:gsub("^%s*||","|")
            while i <= #lines and lines[i]:match("^%s*!") do
    table.insert(r,b)
                table.insert(headers, lines[i])
  end
                i = i + 1
  end
            end
end
            i = i - 1
return table.concat(r,"\n")
            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