Module:StripFilename: Difference between revisions
From Neodyland Wiki
More actions
←Blanked the page |
Undo revision 239901390 by 2001:56A:F6FE:BA00:6D49:E7F9:38DB:8BD1 (talk) |
||
| Line 1: | Line 1: | ||
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 | |||
local e = string.lower(string.gsub(f,"^.*%.([^%.]*)$","%1")) | |||
local map = {svg=1, png=1, jpg=1, jpeg=1, gif=1, tif=1, tiff=1, xcf=1, mid=1, ogg=1, ogv=1, djvu=1, oga=1, flac=1, wav=1, webm=1, pdf=1} | |||
if map[e] | |||
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") | |||
-- Replace underscores with spaces | |||
f = string.gsub(f,"_"," ") | |||
-- Keep, replace with, or add "svg" extension | |||
local e = string.lower(string.gsub(f,"^.*%.([^%.]*)$","%1")) | |||
local map = {png=1, jpg=1, jpeg=1, gif=1, tif=1, tiff=1, xcf=1, mid=1, ogg=1, ogv=1, djvu=1, oga=1, flac=1, wav=1, webm=1, pdf=1} | |||
if e=="svg" | |||
then n = f | |||
elseif map[e] | |||
then n = string.gsub(f,"^(.*)%.[^%.]*$","%1.svg") | |||
else n = f..".svg" | |||
end | |||
return n | |||
end | |||
return p | |||
Revision as of 04:44, 6 April 2017
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
local e = string.lower(string.gsub(f,"^.*%.([^%.]*)$","%1"))
local map = {svg=1, png=1, jpg=1, jpeg=1, gif=1, tif=1, tiff=1, xcf=1, mid=1, ogg=1, ogv=1, djvu=1, oga=1, flac=1, wav=1, webm=1, pdf=1}
if map[e]
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")
-- Replace underscores with spaces
f = string.gsub(f,"_"," ")
-- Keep, replace with, or add "svg" extension
local e = string.lower(string.gsub(f,"^.*%.([^%.]*)$","%1"))
local map = {png=1, jpg=1, jpeg=1, gif=1, tif=1, tiff=1, xcf=1, mid=1, ogg=1, ogv=1, djvu=1, oga=1, flac=1, wav=1, webm=1, pdf=1}
if e=="svg"
then n = f
elseif map[e]
then n = string.gsub(f,"^(.*)%.[^%.]*$","%1.svg")
else n = f..".svg"
end
return n
end
return p