Module:NUMBEROFSECTIONS: Difference between revisions

Content deleted Content added
to be expanded - pushing to module space early due to strange sandbox results
 
a few simple comments and preparedness for expansion
Line 1:
local p = {}
 
-- Counting function accepting a string haystack and table of needles
local function count(rawhaystack, seclevsneedles)
local nosnumber = 0
local index = 1
local levneedle = seclevsneedles[index]
-- While we have needles to look for
while levneedle do
for m in string.gmatch(raw, "\n" .. lev .. "[^=]") do
-- find them all in our haystack
nos = nos + 1
for m in string.gmatch(rawhaystack, "\n" .. lev .. "[^=]"needle) do
nosnumber = nosnumber + 1
end
index = index + 1
levneedle = seclevsneedles[index]
end
return nosnumber
end
 
-- Function accepting a page name and section level numbers
function p.sections(frame)
local levelsneedles = {}
local levellevels = frame.args[2]
local title = mw.title.new(frame.args[1])
-- For every section level number
for valuelevel in mw.text.gsplit(levellevels, "") do
if valuelevel ~= " " then
levels[#levels + 1] = string.rep("=", tonumber(value))
-- add the needle to our table of needles
needles[#needles + 1] = "\n" ..
levels[#levels + 1] = string.rep("=", tonumber(valuelevel)) .. "[^=]"
end
end
-- then return how many needles are in our haystack
return count(title:getContent(), levelsneedles)
end