Bu modulun sənədləşdirmə səhifəsi Modul:Tables/doc səhifəsində yaradıla bilər

 local p = {}

function p.AutoNumBox2(frame)
 
    local g = frame:getParent().args[1]
    local NumStr = tonumber (frame:getParent().args['Başlanğıc'] or "1");
    if g == nil then return "Verilən yoxdur" end
    g = g:gsub(".*{|(.*)|}.*", "%1")
    local Titul = g:sub(1, (g:find ("\n!") or 1) - 1)
    g = g:sub((g:find ("\n!") or 1))
    g = g:gsub("||", "\n|")
    local Pos0 = 0
    while g:find("|%-[^|]*(|[^\n]*\n)", Pos0 + 1) ~= nil do
        Pos1, Pos2 = g:find("|%-[^|]*(|[^\n]*\n)", Pos0 + 1)
        while g:find("|", Pos1 + 1) ~= nil and g:find("|", Pos1 + 1) < Pos2 do
            Pos1 = g:find("|", Pos1 + 1)
        end
        if g:find("%d", Pos1) ~= nil and g:find("%d", Pos1) < Pos2 then
            Pos3, Pos4 = g:find("%d+", Pos1)
            g = g:sub(1, Pos3 - 1)..NumStr..g:sub(Pos4 + 1)
            NumStr = NumStr + 1
        end
        Pos0 = Pos2
    end
    return "{|"..Titul..g.."|}"
end

function p.AutoNumBox ( frame )
    local NumStr = tonumber (frame.args['Başlanğıc'] or "1");
    local g = frame.args[1]
    g = g:gsub("^%s- -{{", "", 1)
    g = g:gsub("}}%s- -$", "", 1)
    pattern = "|%s*#%s*%s*|"
    while string.find (g, pattern) ~= nil do
        g = g:gsub(pattern, "|"..NumStr.."\n".."|", 1)
        NumStr = NumStr + 1
    end
    return g
end

function p.AutoNum ( frame )
    local args = frame.args;
    local Style = (frame.args['Tərtibat'] or "standard");
    local Column = tonumber (frame.args['Sütun'] or "0");
    local NumStr = tonumber (frame.args['Başlanğıc'] or "1");
    local Title0 = (frame.args['Başlıq0'] or "№")
    local Titles = {}
    for i = 1, Column do
        Titles[i] =(frame.args["Başlıq"..i] or "Başlıq"..i)
    end
    local Width0 = (frame.args['Eni0']);
    local Widths = {}
    for i = 1, Column do
        Widths[i] =(frame.args["Eni"..i])
    end
    local Align0 = (frame.args['Yerləşmə0'] or "center")
    local Aligns = {}
    for i = 1, Column do
        Aligns[i] =(frame.args["Yerləşmə"..i] or "left")
    end

    local g="<table class = '"..Style.."'>"
    
    g = g.."<tr>"

    g = g.."<th"; if Width0 ~= nil then g = g.." width='"..Width0.."'" end; g = g..">"
    g = g..Title0.."</th>"

    for i = 1, Column do
        g = g.."<th"; if Widths[i] ~= nil then g = g.." width='"..Widths[i].."'" end; g = g..">"
        g = g..Titles[i].."</th>"
    end
    g = g.."</tr>"
    
    J = 1
    while args[(J-1)*Column+1] ~= nil do
        g = g.."<tr><td align='"..Align0.."'>"..NumStr.."</td>"
        for i = 1, Column do
             if args[(J-1)*Column+i] == nil then
                g = g.."<td></td>"
            else
                g = g.."<td align='"..Aligns[i].."'>"..args[(J-1)*Column+i].."</td>"
             end
        end
        g = g.."</tr>"
        NumStr = NumStr + 1
        J = J + 1
    end

    g = g.."</table>"
    return g
end

function p.AutoNumSort(frame)

    local args = frame:getParent().args
    local Column = tonumber(args['Sütun'] or "0")
        if Column == 0 then return "Sütunların sayılması mümkün deyil" end
    local TempSort = (args['Sıralama'] or "0")
    local SortColumn = tonumber(string.match(TempSort, "%d*")) or 0
        if SortColumn > Column then SortColumn = 0 end
    local SortAsNumber = string.match(TempSort, "#") ~= nil
    local SortDescend
        if SortAsNumber
        then SortDescend = string.find(TempSort, "<") == nil
        else SortDescend = string.find(TempSort, ">") ~= nil end

    local Strings={}
    local NumCell = 0

    while args[NumCell + 1] ~= nil or NumCell%Column ~= 0 do
        NumCell = NumCell + 1
    	if (args[NumCell] == nil) then args[NumCell]="" end
    	if NumCell%Column == 0 then
    		local TempString = {NumCell-Column+1}
            if SortAsNumber then
                KeyCell=args[TempString[1]+SortColumn-1]
				KeyCell=mw.ustring.gsub(KeyCell, "<span[^<]+</span>","")
				KeyCell=mw.ustring.gsub(KeyCell, ",",".")
				KeyCell=mw.ustring.gsub(KeyCell, " ","")
				KeyCell=mw.ustring.gsub(KeyCell, "&nbsp;","")
				KeyCell=mw.ustring.gsub(KeyCell, "%s","")
				KeyCell=mw.ustring.match(KeyCell, "^%D*(%d+%.?%d*)") or ""
	            TempString.Key=tonumber(KeyCell)
            elseif SortColumn > 1 then
                TempString.Key = (args[TempString[1]+SortColumn-1] or "")
                TempString.Key = mw.ustring.gsub(TempString.Key, '<span[^>]*>', "")
                TempString.Key = mw.ustring.gsub(TempString.Key, "ё", "е")
                TempString.Key = mw.ustring.gsub(TempString.Key, "Ё", "Е")
                -- trim
                TempString.Key = mw.ustring.gsub(TempString.Key, "^%s*(.-)%s*$", "%1")
            else TempString.Key = tonumber(TempString[1]) end
            TempString.Group = mw.ustring.gsub(args[TempString[1]], "[^a-zA-Zа-яА-Я0-9]", "")
            table.insert(Strings, TempString)
        end
    end

    local function SortString(a, b)
        if a.Group ~= b.Group then return a.Group < b.Group end
        if SortDescend then a, b = b, a end
        if SortAsNumber or (SortColumn < 2) then
            return a.Key < b.Key
        else
            local LenA = mw.ustring.len(a.Key)
            local LenB = mw.ustring.len(b.Key)
            for i = 1, (LenA < LenB) and LenA or LenB do
                if mw.ustring.codepoint(a.Key, i, i) ~= mw.ustring.codepoint(b.Key, i, i) then
                    return mw.ustring.codepoint(a.Key, i, i) < mw.ustring.codepoint(b.Key, i, i)
                end
            end
            return LenA < LenB
        end
    end

    table.sort(Strings, SortString)

    local HTML = mw.html.create('table')

    HTML:attr('class', (args['Tərtibat'] or "standard"))
    
    if args['Əl ilə tərtibat']~=('' or nil) then
    	HTML:attr('style', args['Əl ilə tərtibat'])
    end

    if args['Adı'] then
		TempCaption=HTML:tag('th')
			:wikitext(args['Adı'])
			:attr('colspan', Column)
    end

    local TempRow
    TempRow = HTML:tag('tr')
    TempHeader=TempRow:tag('th') 
    if args["Eni1"] then  TempHeader:css('width', (args["Eni1"])) end
    TempHeader:wikitext(args['Başlıq1'] or "№")
    
    for i = 2, Column do
        TempColumn=TempRow:tag('th')
        if args["Eni"..i] then TempColumn:css('width', (args["Eni"..i])) end
        TempColumn:wikitext(args["Başlıq"..i] or "Başlıq"..i)
		if args["Sıralama"..i]=="sıralamasız" then
			TempColumn:addClass('unsortable')
		elseif args["Sıralama"..i]=="nömrə" then
			TempColumn:attr('data-sort-type', 'number')
		elseif args["Sıralama"..i]=="дата" then
			TempColumn:attr('data-sort-type', 'date')
		end
	end

    local HideNum = 0
	local NumStr = tonumber (args['Başlanğıc'] or "1") - 1
    local Backlight = (args['Fon'] or "class='bright'"):gsub("\"", "'")
	for Index, TempString in pairs(Strings) do
        TempRow = HTML:tag('tr')
        local first = args[TempString[1]]

        if string.find(first, "%$") ~= nil then TempRow:attr('class', 'shadow')
        elseif string.find(first, "%%") ~= nil then TempRow:attr('class', 'bright')
        elseif string.find(first, "@") ~= nil then TempRow:attr('class', 'dark')
        elseif string.find(first, "%+") ~= nil then
            for Part in string.gmatch(Backlight, "[%w]*=%s*'[^']*'") do
                TempRow:attr(string.match(Part, "([^=]*)="), string.match(Part, "'([^']*)'"))
            end
        end
        if string.find(first, "!") ~= nil then TempRow:attr('style', 'font-weight:bold') end

        if string.find(first, "-") ~= nil then
            HideNum = HideNum + 0.000001
            TempRow:tag('td')
                :tag('span')
                :attr('style', 'display: none; speak: none;')
                :wikitext( tonumber(NumStr + HideNum))
        else
            NumStr = NumStr + 1
            TempRow:tag('td')
                :attr('align', (args['Yerləşmə1'] or "center") )
                :wikitext(tonumber(NumStr))
        end
		for i = 2, Column do
            TempTd=TempRow:tag('td')
            KeyCell=""
			if args["Sıralama"..i]=="nömrə" then
				KeyCell=mw.ustring.gsub(args[TempString[1]+i-1], ",",".")
				KeyCell=mw.ustring.gsub(KeyCell, "&nbsp;","")
				KeyCell=mw.ustring.gsub(KeyCell, "<span[^<]+</span>","")
				KeyCell=mw.ustring.gsub(KeyCell, "%s","")
				KeyCell=mw.ustring.match(KeyCell, "^%D*(%d+%.?%d*)") or ""
	            TempTd:attr('data-sort-value', KeyCell)
			end
            TempTd:wikitext(args[TempString[1]+i-1])
            TempTd:attr('align', args["Yerləşmə"..i] or "left")
		end
    end
    return tostring(HTML)
end

return p