Jump to content
Toggle menu
  • 8 articles
  • 75 files
  • 7 users
  • 37.8K edits
Neodyland Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:StripFilename: Difference between revisions

From Neodyland Wiki
Created page with 'local p = {} function p.main(frame) local f = frame["args"][1] -- Remove namespace prefix f = string.gsub(f,"^[Ff][Ii][Ll][Ee]:(.*)$","%1") f = string....'
 
mp3 is enabled
 
(11 intermediate revisions by 3 users not shown)
Line 3: Line 3:
function p.main(frame)
function p.main(frame)
   local f = frame["args"][1]
   local f = frame["args"][1]
  -- Strip whitespace at beginning and end of input
  f = string.gsub(f,"^%s*(.-)%s*$","%1")
   -- Remove namespace prefix
   -- Remove namespace prefix
   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"))
   local 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')
   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, mp3=1}
     then n = string.gsub(f,"^(.*)%.[^\.]*$","%1")
  if map[e]
     then n = string.gsub(f,"^(.*)%.[^%.]*$","%1")
     else n = f
     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, mp3=1}
  if e=="svg"
    then n = f
  elseif map[e]
    then n = string.gsub(f,"^(.*)%.[^%.]*$","%1.svg")
    else n = f..".svg"
   end
   end
   return n
   return n

Latest revision as of 03:23, 13 July 2018

Module documentation[ create · purge ]
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, mp3=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, mp3=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
Cookies help us deliver our services. By using our services, you agree to our use of cookies.