Open main menu
Home
Random
Donate
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Sandbox/Wnt/TextMarkup
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
---- 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.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 return output end return p
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Sandbox/Wnt/TextMarkup/doc
(
edit
)