Home
Random
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Sandbox/S-1-5-7/versiontests
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!
local module = {}; --All lua modules on Wikipedia must begin by defining a variable --that will hold their externally accessible functions. --Such variables can have whatever name you want and may --also contain various data as well as functions. function get_raw_text(str) local builder = "" for index=1,string.len(str),1 do local ch = string.sub(str,index,index) if ( ch == ' ' or ch == ',' or ch == '.' or ch == '-' or ch == '_' or ch == '&' or ch == '#' or ch == ';' or ch == '(' or ch == ')' or (ch >= '0' and ch <= '9') or (ch >= 'A' and ch < 'Z') or ( ch >= 'a' and ch < 'z') ) then builder = builder .. ch else builder = builder .. "\\" .. ch .. " (" .. string.byte(ch,1) .. ")" end end return builder end function module.extract_version(frame) local base = frame.args[1] local stripAdditional = frame.args[2] -- remove the markers base = mw.text.killMarkers(base) -- the version is in the version beginning and is separated by '(' local version = string.match(base, "^%s*([^(]+)%s*%(", 1, true) if version == nil then return "No version?" end -- it seems like match() doesn't support non-greedy captures, so just -- strip the whitespaces version = mw.text.trim(version) -- sometimes there is text that is put in front of it like -- Version 2019 24.2.2 -- and we optionally want to remove that if stripAdditional == "true" then test = string.find(version, " ") while ( test ~= nil ) do version = string.sub(version, test + 1, string.len(version)) test = string.find(version, " ") end end -- done return version end function module.extract_date(frame) local base = frame.args[1] local format = frame.args[2] -- remove the markers base = mw.text.killMarkers(base) -- remove HTML entities base = mw.text.decode(base) -- if they request it in raw format, just extract it if format == nil or format == "raw" then -- remove spans --base = base:gsub("<span[^>]*>", "") --base = base:gsub("</span>", "") -- look for "ago" to get the date part local datepart = base:match("%(([^)]*);[^)]*ago") if datepart == nil then return "No date?" end -- remove any extra space datepart = mw.text.trim(datepart) return datepart else -- extract the "dtstart" part local datepart = base:match("%(([^)]*);[^)]*ago") -- parse it; dates usually are in the form: -- Month Year -- Month Day, Year -- Day Month Year -- TODO -- and convert it to the -- done return "TODO" end end function module.debug_get_raw_text(frame) local base = frame.args[1] base = mw.text.killMarkers(base) local builder = get_raw_text(base) return "<pre>" .. builder .. "</pre>" end return module
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/S-1-5-7/versiontests/doc
(
edit
)