Content deleted Content added
m 7 |
trim and more strip |
||
Line 719:
end
-- Strips whitespace from an input
function trim(value)
return s:gsub('^%s*(.-)%s*$', '%1')
end
function stripFieldExtras(value)
-- todo: do progressive scan like with that seek string just for ref tags and such
local matchNoRef = value:match('^([^<]+)<ref[^>]*>[^<]*</ref><ref[^>]*>[^<]*</ref><ref[^>]*>[^<]*</ref>$') -- basic
if (matchNoRef) then return trim(matchNoRef) end
matchNoRef = value:match('^([^<]+)<ref[^>]*>[^<]*</ref><ref[^>]*>[^<]*</ref>$') -- basic
if (matchNoRef) then return trim(matchNoRef) end
matchNoRef = value:match('^([^<]+)<ref[^>]*>[^<]*</ref>$') -- basic
if (matchNoRef) then return trim(matchNoRef) end
matchNoRef = value:match('^([^<]+)<ref[^>]*/><ref[^>]*/><ref[^>]*/>$') -- basic named ref
if (matchNoRef) then return trim(matchNoRef) end
matchNoRef = value:match('^([^<]+)<ref[^>]*/><ref[^>]*/>$') -- basic named ref
if (matchNoRef) then return trim(matchNoRef) end
matchNoRef = value:match('^([^<]+)<ref[^>]*/>$') -- basic named ref
if (matchNoRef) then return trim(matchNoRef) end
matchNoRef = value:match('^<!--.?-->([^<]+)$') -- comment before
if (matchNoRef) then return trim(matchNoRef) end
matchNoRef = value:match('^([^<]+)<!--.?-->$') -- comment after
if (matchNoRef) then return trim(matchNoRef) end
return value
Line 762 ⟶ 782:
end
input = stripFieldExtras(trim(input))
-- If there is nothing but whitespace, don't bother
Line 812 ⟶ 832:
function main.outputRawStripped(frame)
return stripFieldExtras(trim(mw.text.decode(mw.text.unstrip(frame.args[1]))))
end
|