İçeriğe atla

Modül:Wikitext

Vikipedi, özgür ansiklopedi
Modül belgelemesi[oluştur]
specns={file='file',image='file',category='cat',
    ['k']='cat',['kategori']='cat',['dosya']='file',['resim']='file'}

linkprefs="http:// gopher:// https:// mailto: news:// ftp:// irc:// //"

local function Delink(text,repl,cat,file,href,colon)
    return ( 
        mw.ustring.gsub(text, "%[%[(%s*([^|%]]+)%s*)|?(.-)%]%](%a*)", function(a,l,c,e)
        l = l:gsub("%s+"," ");
        if specns[mw.ustring.lower(l):match("^(.*):")] then
            if specns[mw.ustring.lower(l):match("^(.*):")]=='cat' then
                if cat then
                    return table.concat{ l:gsub("^.-:%s*",''), '|', c }:gsub( "^(.-)|([^|]*)|?(.-)$", cat ) .. e
                else 
                    return e
                end
            else
                if  file then
                    return table.concat{ l:gsub("^.-:%s*",''), '|', c }:gsub( "^(.-)|(.*)", file ) .. e
                else return e
                end
            end
        end
        l=string.gsub(l,"^: *", colon or "%1");
        if repl then
            return mw.ustring.gsub(l..'|'..(c=='' and a..e or c..e),"^(.-)|(.*)$",repl)
        else
            if c=='' then return a..e else return c..e end
        end
    end
):gsub(
    "(%[([%a%._\/~%%%-%+&#%?!=%(%)@]+)%s*(.-)%])", function(a,r,t)
        local p,i=r:match('^(%a*:?//)(.*)')
        if not p then p,i=r:match('^(mailto:)(.*)') end
        if p then
            if href then
                return (p..' '..i..' '..t):gsub("^(.-) (.-) (.*)$",href) 
            else
                return t
            end
        else
            return a
        end
    end
) )
end

local function Detag(t)
    if t == nil or t == '' then
    	return ''
    end
    local text,j,i,k=t,0;
    repeat 
        text,i=text:gsub('(</?%a[^>"\']*")[^"]*\\["\\]',"%1");
        text,k=text:gsub("(</?%a[^>\"']*')[^']*\\['\\]","%1");
        if i+k==0 then
            text,j=text:gsub("(</?%a[^>]*)(['\"]).-%2","%1")
        end
    until i+j+k==0
    return (text:gsub("'''?",""):gsub('</?%a[^>]*>',''))
end

local function Nodis(t)
    return (t:gsub('%s*%([^%)]+%)$',''))
end


return {
delink=function(f)
    local tf=f:getParent()
    return Delink(
        f.args[1] or tf.args[1],
        f.args['repl'] or tf.args['repl'],
        f.args['cat'] or tf.args['cat'],
        f.args['file'] or tf.args['file'],
        f.args['href'] or tf.args['href'],
        f.args[':'] or tf.args[':']
        )
end; Delink=Delink;

detag=function(f)
    return Detag(f.args[1] or f:getParent().args[1])
end; Detag=Detag;

plain=function(f)
    local tf=f:getParent()
    return Detag(Delink(
        f.args[1] or tf.args[1],
        f.args['repl'] or tf.args['repl'],
        f.args['cat'] or tf.args['cat'],
        f.args['file'] or tf.args['file'],
        f.args['href'] or tf.args['href'],
        f.args[':'] or tf.args[':']
        ));
end;

nodis=function(f)
    return Nodis(f.args[1] or f:getParent().args[1])
end;Nodis=Nodis
}