Home
Random
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Sandbox/Alex 21
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 p = {} local escape = require("Module:String")._escapePattern function trimspaces(s) return string.gsub(s, "^%s*(.-)%s*$", "%1") end local function getTitle(title) local success, titleObj = pcall(mw.title.new, title) if success then return titleObj else return nil end end function p.main(frame) local args = require('Module:Arguments').getArgs(frame, { wrappers = 'Template:Template parameter value' }) local template = escape(args[2]) local parameter = escape(args[4]) local numberedParameter = (tonumber(parameter) ~= nil) local templateCount = 0 local parameterCount = 0 local templateMatch = tonumber(args[3] or 1) local parameterMatch = tonumber(args[5] or 1)*(numberedParameter and parameter or 1) local targettitle = getTitle(args[1]) if targettitle == nil then return "" end local content = string.gsub(targettitle:getContent() or "", "[\r\n]", "") while templateCount ~= templateMatch do if content == nil then return "" end content = string.match(content, '{{' .. template .. "(.+)") templateCount = templateCount + 1 end while parameterCount ~= parameterMatch do if content == nil then return "" end content, content_rest = string.match(content, '|%s*' .. (numberedParameter and "" or (parameter .. '%s*=%s*')) .. '([^|]*)(.*)') while string.match(content, '^[^%]]*%[%[[^%]]+$') or string.match(content, '^[^%}]*%{%{[^%}]+$') do content_match, content_rest = string.match(content_rest, '(.[^|]*)(.*)') content = content .. content_match end parameterCount = parameterCount + 1 end content = string.match(content, '^([^%{]*)%}%}') or content content = string.match(content, '^(.+)%{%{[^%}]*$') or content local _, countL = string.gsub(content, "%{%{", "") local _, countR = string.gsub(content, "%}%}", "") local countDiff = math.abs(countL-countR) while countDiff > 0 do content = string.match(content, '^(.*)%}%}$') or content countDiff = countDiff - 1 end if content == nil then return "" end content = string.gsub(content, "</?%a*include%a*>", "") content = string.gsub(content, "^%d+=", "") content = frame:preprocess{text = content} content = trimspaces(content) return content 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)
Templates used on this page:
User:Alex 21/Tabs
(
edit
)
Module:Sandbox/Alex 21/doc
(
edit
)