Module:Sandbox: Difference between revisions

Jump to navigation Jump to search
(Created page with "local getArgument = require('Module:Arguments').getArgument local p = {} function trim(s) -- Allows removing of whitespace and line breaks from inputs; adapted from (https://www.lua.org/manual/2.4/node32.html) local l = 1 while string.sub(s,l,l) == ' ' do l = l+1 end while string.sub(s,l,l+1) == '\n' do l = l+2 end local r = string.len(s) while string.sub(s,r,r) == ' ' do r = r-1 end while string.sub(s,r,r-1) == '\n' do r = r-2 end return string.sub(s,l,...")
 
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 22: Line 22:


function p.Main(frame)
function p.Main(frame)
local oArgs = frame:getParent().args
local args = frame.args
local args = {}
for k, v in pairs(oArgs) do
v = v:match('^%s*(.-)%s*$')
if v ~= '' then
args[k] = v
end
end
local tabcontent = args[1]
local tabcontent = args[1]
tabcontent = mw.text.killMarkers(tabcontent)
tabcontent = '\n' .. mw.text.unstripNoWiki(tabcontent) .. '\n'
return tabcontent
return tabcontent
end
end


return p
return p

Latest revision as of 22:19, 16 July 2024

Documentation for this module may be created at Module:Sandbox/doc

local getArgument = require('Module:Arguments').getArgument

local p = {}

function trim(s) -- Allows removing of whitespace and line breaks from inputs; adapted from (https://www.lua.org/manual/2.4/node32.html)
	local l = 1
	while string.sub(s,l,l) == ' ' do
	l = l+1
	end
	while string.sub(s,l,l+1) == '\n' do
	l = l+2
	end
	local r = string.len(s)
	while string.sub(s,r,r) == ' ' do
	r = r-1
	end
	while string.sub(s,r,r-1) == '\n' do
	r = r-2
	end
	return string.sub(s,l,r)
end

function p.Main(frame)
	local args = frame.args
	local tabcontent = args[1]
	tabcontent = '\n' .. mw.text.unstripNoWiki(tabcontent) .. '\n'
	return tabcontent
end

return p