Module:Sandbox/Wnt/TextMarkup

 ---- 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

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.