Przejdź do zawartości

Moduł:Sandbox/Draco flavus/SectionBorders

Z Wikiźródeł, wolnej biblioteki

Dokumentacja dla tego modułu może zostać utworzona pod nazwą Moduł:Sandbox/Draco flavus/SectionBorders/opis

-- Jeśli konsekwentnie tworzone są granice rozdziałów przy pomocy pustych sekcji (bezpośrednio przed następnym rozdziałem - po ostatnim rozdziale ewentualnie  -na końcu)
-- Mają one nazwę X (i nie ma dwóch początków rozdziałów na jednej stronie)
-- można półautomatycznie tworzyć rozdziały, kontrolując jednak zawsze poprawność utworzeonego (traksludowanego) rozdziału

local p = {}

local escape_lua_pattern
do
  local matches =
  {
    ["^"] = "%^";
    ["$"] = "%$";
    ["("] = "%(";
    [")"] = "%)";
    ["%"] = "%%";
    ["."] = "%.";
    ["["] = "%[";
    ["]"] = "%]";
    ["*"] = "%*";
    ["+"] = "%+";
    ["-"] = "%-";
    ["?"] = "%?";
  }

  escape_lua_pattern = function(s)
    return (s:gsub(".", matches))
  end
end

local function PrepareListOfSections(page,number_start,number_end,index_name,chapter)
	local SubPageResult = ""
    local n = tonumber(number_start)
    local m = tonumber(number_end)
    local p = '<section  *begin *= *"?X"? */><section  *end *= *"?X"? */>.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?' 
    local q = '[^A-Za-z0-9=]' .. chapter .. '[^A-Za-z0-9%%]'
    local SubPageName=""
    local FirstPage={}
    local LastPage={}
    local ListOfItems="◇"
    local position=0
    local wynik=''
    local wynik1=''
    local wynik2=''
    local ListOfPages={}
    while (n <= m) do
    	
    	--
    
    	SubPageName='Strona:' .. page .. "/" .. n
    	if mw.title.new(SubPageName):getContent() ~= nil then
    		if (string.match(mw.title.new(SubPageName):getContent(), p) ~= nil ) then
    			SubPageResult = SubPageResult .. string.char(10) .. string.char(10) .. "𝕬".. n .. "◇" .. string.match(mw.title.new(SubPageName):getContent(),  p ) .. '𝖅'
    		end
		end
    	--
		n = n + 1
		SubPageName=page .. "/" .. n
    end
    
    wynik = string.match(SubPageResult, '𝕬[^𝕬]*'.. q .. '.-◇')

    wynik1 = string.gsub(wynik, '𝕬(%d*)◇.-𝕬%d*◇', '%1')
    wynik2 = string.gsub(wynik, '𝕬%d*◇.-𝕬(%d*)◇', '%1')
    


	if page ~=index_name then
		wynik1 = '"' .. page .. '/' .. wynik1 .. '"'
		wynik2 = '"' .. page .. '/' .. wynik2 .. '"'
	end

	return '<pages index="' .. index_name .. '" from=' .. wynik1 .. ' to=' .. wynik2 .. ' fromsection="X" tosection="X" />'

end
local function only_last_part(nazwa)
	local wynik
	
	wynik = string.gsub(nazwa,'.*[/ ]([^ ]*)','%1')
	return wynik
end
	
	
function p.all(frame)
local s=PrepareListOfSections(frame.args[1],frame.args[2],frame.args[3],frame.args[4], only_last_part(frame.args[5]))
-- s = only_last_part(frame.args[5])
return s
end
return p