Module:StripFilename: Difference between revisions
From Neodyland Wiki
More actions
No edit summary |
No edit summary |
||
| Line 8: | Line 8: | ||
f = string.gsub(f,"^[Ff][Ii][Ll][Ee]:(.*)$","%1") | f = string.gsub(f,"^[Ff][Ii][Ll][Ee]:(.*)$","%1") | ||
f = string.gsub(f,"^[Ii][Mm][Aa][Gg][Ee]:(.*)$","%1") | f = string.gsub(f,"^[Ii][Mm][Aa][Gg][Ee]:(.*)$","%1") | ||
-- Remove extension | -- Remove any recognized extension | ||
e = string.lower(string.gsub(f,"^.*%.([^%.]*)$","%1")) | e = string.lower(string.gsub(f,"^.*%.([^%.]*)$","%1")) | ||
if (e== | if (e=="svg" or e=="png" or e=="jpg" or e=="jpeg" or e=="gif" or e=="tif" or e=="tiff" or e=="xcf" or e=="mid" or e=="ogg" or e=="ogv" or e=="djvu" or e=="oga" or e=="flac" or e=="wav" or e=="webm" or e=="pdf") | ||
then n = string.gsub(f,"^(.*)%.[^%.]*$","%1") | then n = string.gsub(f,"^(.*)%.[^%.]*$","%1") | ||
else n = f | else n = f | ||
| Line 24: | Line 24: | ||
f = string.gsub(f,"^[Ff][Ii][Ll][Ee]:(.*)$","%1") | f = string.gsub(f,"^[Ff][Ii][Ll][Ee]:(.*)$","%1") | ||
f = string.gsub(f,"^[Ii][Mm][Aa][Gg][Ee]:(.*)$","%1") | f = string.gsub(f,"^[Ii][Mm][Aa][Gg][Ee]:(.*)$","%1") | ||
-- | -- Keep, replace with, or add "svg" extension | ||
e = string.gsub(f,"^.*%.([^%.]*)$","%1") | e = string.lower(string.gsub(f,"^.*%.([^%.]*)$","%1")) | ||
if | if e=="svg" | ||
then n = f | then n = f | ||
elseif (e=="png" or e=="jpg" or e=="jpeg" or e=="gif" or e=="tif" or e=="tiff" or e=="xcf" or e=="mid" or e=="ogg" or e=="ogv" or e=="djvu" or e=="oga" or e=="flac" or e=="wav" or e=="webm" or e=="pdf") | |||
then n = string.gsub(f,"^(.*)%.[^%.]*$","%1.svg") | |||
else n = f..".svg" | |||
end | end | ||
return n | return n | ||
Revision as of 13:15, 28 March 2015
This documentation is transcluded from Module:StripFilename/doc.
local p = {}
function p.main(frame)
local f = frame["args"][1]
-- Strip whitespace at beginning and end of input
f = string.gsub(f,"^%s*(.-)%s*$","%1")
-- Remove namespace prefix
f = string.gsub(f,"^[Ff][Ii][Ll][Ee]:(.*)$","%1")
f = string.gsub(f,"^[Ii][Mm][Aa][Gg][Ee]:(.*)$","%1")
-- Remove any recognized extension
e = string.lower(string.gsub(f,"^.*%.([^%.]*)$","%1"))
if (e=="svg" or e=="png" or e=="jpg" or e=="jpeg" or e=="gif" or e=="tif" or e=="tiff" or e=="xcf" or e=="mid" or e=="ogg" or e=="ogv" or e=="djvu" or e=="oga" or e=="flac" or e=="wav" or e=="webm" or e=="pdf")
then n = string.gsub(f,"^(.*)%.[^%.]*$","%1")
else n = f
end
return n
end
function p.svg(frame)
local f = frame["args"][1]
-- Strip whitespace at beginning and end of input
f = string.gsub(f,"^%s*(.-)%s*$","%1")
-- Remove namespace prefix
f = string.gsub(f,"^[Ff][Ii][Ll][Ee]:(.*)$","%1")
f = string.gsub(f,"^[Ii][Mm][Aa][Gg][Ee]:(.*)$","%1")
-- Keep, replace with, or add "svg" extension
e = string.lower(string.gsub(f,"^.*%.([^%.]*)$","%1"))
if e=="svg"
then n = f
elseif (e=="png" or e=="jpg" or e=="jpeg" or e=="gif" or e=="tif" or e=="tiff" or e=="xcf" or e=="mid" or e=="ogg" or e=="ogv" or e=="djvu" or e=="oga" or e=="flac" or e=="wav" or e=="webm" or e=="pdf")
then n = string.gsub(f,"^(.*)%.[^%.]*$","%1.svg")
else n = f..".svg"
end
return n
end
return p