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 >= '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 builderend
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
"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 versionend
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
"raw" then -- remove spans --base = base:gsub("
]*>", "") --base = base:gsub("", "") -- look for "ago" to get the date part local datepart = base:match("%(([^)]*);[^)]*ago") if datepart-- 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" endend
function module.debug_get_raw_text(frame) local base = frame.args[1] base = mw.text.killMarkers(base) local builder = get_raw_text(base) return "
" .. builder .. ""end
return module