Module:Delimited tag: Difference between revisions

From Modded Wiki
Jump to navigation Jump to search
No edit summary
merge serialDelimiter
Line 25: Line 25:
['to'] = ' to ',
['to'] = ' to ',
['br'] = '<br/>',
['br'] = '<br/>',
['newline'] = '<br/>',
['newline'] = '<br>',
['list'] = '<br/>' .. listLevel,
['list'] = '\n' .. listLevel,
['bullet'] = '<br/>' .. listLevel,
['bullet'] = '\n' .. listLevel,
['*'] = '<br/>' .. listLevel,
['*'] = '\n' .. listLevel,
['and-list'] = ' and<br/>' .. listLevel,
['and-list'] = ', and\n' .. listLevel,
['or-list'] = ' or<br/>' .. listLevel,
['or-list'] = ', or\n' .. listLevel,
['&-list'] = ' &<br/>' .. listLevel,
['&-list'] = ' &\n' .. listLevel,
['amp-list'] = ' &<br/>' .. listLevel,
['amp-list'] = ' &\n' .. listLevel,
['comma-list'] = ',<br/>' .. listLevel,
['comma-list'] = ',\n' .. listLevel,
[',-list'] = ',<br/>' .. listLevel,
[',-list'] = ',\n' .. listLevel,
}
}
Line 43: Line 43:
['and-list'] = ',<br>\n' .. listLevel,
['and-list'] = ',<br>\n' .. listLevel,
['&-list'] = ',<br>\n' .. listLevel,
['&-list'] = ',<br>\n' .. listLevel,
}
local delimitersWithSerial = {
['and'] = true,
['or'] = true,
['and-list'] = true,
['&-list'] = true,
['or-list'] = true
}
}
local delimiter = args['delimiter'] or args['delim'] or args['d'] or '&nbsp;'
local delimiter = args['delimiter'] or args['delim'] or args['d'] or '&nbsp;'
if finalDelimiterValues[delimiter] then delimiter = finalDelimiterValues[delimiter] end
local finalDelimiter = finalDelimiterValues[delimiter] or delimiter
local midDelimiter = midDelimiterValues[delimiter] or delimiter
local midDelimiter = midDelimiterValues[delimiter] or delimiter
local serialDelimiter = delimitersWithSerial[delimiter] and ',' or ''
for i,unit in ipairs(args) do
for i,val in ipairs(args) do
if (i > 1) then
if (i > 1) then
local currentDelimiter = args[i*1+1] and midDelimiter or (serialDelimiter .. delimiter)
local currentDelimiter = args[i+1] and midDelimiter or finalDelimiter
output = output .. currentDelimiter .. tag(args[i])
output = output .. currentDelimiter .. tag(val)
end
end
end
end

Revision as of 03:48, 5 December 2020

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

local p = {}

function p.output(f)

	local args = f
	if f == mw.getCurrentFrame() then 
		args = require('Module:ProcessArgs').merge(true)
	end

	local tag = function(txt)
		return '<' .. args['tag'] .. '>' .. txt .. '</' .. args['tag'] .. '>'
	end
	local listLevel = args['list-level'] or '**'

	local output = tag(args[1])
	
	local finalDelimiterValues = {
		['none'] = '<nowiki/>',
		['comma'] = ',&#32;',
		 [','] = ',&#32;',
		['and'] = ' and&#32;',
		['&'] = ' &amp;&nbsp;',
		 ['amp'] = ' &amp;&nbsp;',
		['or'] = ' or&nbsp;',
		['to'] = ' to&nbsp;',
		['br'] = '<br/>',
		 ['newline'] = '<br>',
		['list'] = '\n' .. listLevel,
		 ['bullet'] = '\n' .. listLevel,
		 ['*'] = '\n' .. listLevel,
		['and-list'] = ', and\n' .. listLevel,
		['or-list'] = ', or\n' .. listLevel,
		['&-list'] = ' &\n' .. listLevel,
		['amp-list'] = ' &\n' .. listLevel,
		['comma-list'] = ',\n' .. listLevel,
		 [',-list'] = ',\n' .. listLevel,
	}
	
	local midDelimiterValues = {
		['and'] = ', ',
		 ['&'] = ', ',
		 ['amp'] = ', ',
		['and-list'] = ',<br>\n' .. listLevel,
		 ['&-list'] = ',<br>\n' .. listLevel,
	}
	
	local delimiter = args['delimiter'] or args['delim'] or args['d'] or '&nbsp;'
	local finalDelimiter = finalDelimiterValues[delimiter] or delimiter
	local midDelimiter = midDelimiterValues[delimiter] or delimiter
	
	for i,val in ipairs(args) do
		if (i > 1) then
			local currentDelimiter = args[i+1] and midDelimiter or finalDelimiter
			output = output .. currentDelimiter .. tag(val)
		end
	end
	
	return output
	
end

return p