Modul:Matematik för årskurs 7-9/Test
Utseende
Documentation for Modul:Matematik för årskurs 7-9/Test
Testmodul att leka med
---- This module accepts a piece of text or the name of a page
---- It acts on angle-bracket tags in the text to simulate an extension of the html/wiki markup set
---- Vaguely per [[WP:Lua requests]], the <inc> tag is the first example, replaced with a number
---- that increases each count. You can set or reset the count and rate at any time by <inc i j>
---- where i=the number of that tag and j is the difference to succeeding tags.
local p={}
function p.go(frame)
output, n = mw.ustring.gsub(frame.args[1],"no","")
return output, n
end
function extrude(input)
output, n = mw.ustring.gsub(input,"<noinclude>.-</noinclude>","") -- remove noincludes
return output
end
function p.markup(frame)
local args=frame.args
local parent=frame.getParent(frame) or {}
pargs=parent.args or {}
local text=args.text or pargs.text
local page=args.page or pargs.page
if (not text and not page) then
if not args[1] then return "" end
if mw.ustring.match(args[1],"<inc>") then text=args[1] else page=args[1] end
end
if not text then
page=mw.ustring.match(page,"%s*(.*%S)%s*") or ""
if page=="" then
title=mw.title.getCurrentTitle()
assert(title.getContent, "Bug: [[Module:TextMarkup]] failed to get content of the current page")
page=title.fullText
else title=mw.title.new(page)
assert(title.getContent, "Error: [[Module:TextMarkup]] failed to get content of "..page)
end -- one way or another, we have a working getContent method
text=title.getContent(title)
end -- (not text) -- now we have text
local counter=0 -- set counter to zero before encountering an <inc> tag
local increment=1 -- default increment
local prowl=mw.ustring.gmatch(text,"<inc([^>]*)>") -- iterator function to get all the tags
local output=text -- copy to do substitutions on
repeat
local inccontent=prowl()
if not inccontent then break end -- loop exit
local n1,n2 = mw.ustring.match(text,"%D-(%d+)%D-(%d+)")
if n2 then increment=tonumber(n2) end
counter=counter+increment
if n1 then counter=tonumber(n1) end
output=mw.ustring.gsub(output,"<inc([^>]*)>",tostring(counter),1) -- change one instance according to the one instance found
until false
output = extrude(output)
output = frame:preprocess(output)
return output
end
return p