Module:RemoveMiddleColumn: Difference between revisions
Appearance
imported>Ziebster No edit summary |
imported>Ziebster No edit summary |
||
| Line 1: | Line 1: | ||
local p={} | local p={} | ||
function p.slim( | function p.slim(frame) | ||
local | local text=frame.args[1]or"" | ||
if | if text==""then return""end | ||
local | local lines={} | ||
for | for line in text:gmatch("([^\n])\n?")do | ||
local | table.insert(lines,line) | ||
local | end | ||
for _, | local result={} | ||
if | local col_count=0 | ||
elseif | local in_table=false | ||
elseif | local is_header=false | ||
elseif | for _,line in ipairs(lines)do | ||
if | 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 | 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 | |||
table.insert(result,line) | |||
end | end | ||
else | else | ||
table.insert(result,line) | |||
end | end | ||
end | end | ||
return table.concat( | return table.concat(result,"\n") | ||
end | end | ||
return p | return p | ||
Revision as of 14:43, 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 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