Module:Delimited tag: Difference between revisions

From Modded Wiki
Jump to navigation Jump to search
skip first go-around
No edit summary
Line 17: Line 17:
local finalDelimiterValues = {
local finalDelimiterValues = {
['none'] = '<nowiki/>',
['none'] = '<nowiki/>',
[','] = ',&#32;',
['comma'] = ',&#32;',
['and'] = '&#32;and&#32;',
[','] = ',&#32;',
['&'] = '&nbsp;&amp;&nbsp;', ['amp'] = '&nbsp;&amp;&nbsp;',
['and'] = ' and&#32;',
['or'] = '&#32;or&nbsp;',
['&'] = ' &amp;&nbsp;',
['to'] = '&#32;to&nbsp;',
['amp'] = ' &amp;&nbsp;',
['br'] = '<br/>', ['newline'] = '<br/>',
['or'] = ' or&nbsp;',
['list'] = '<br/>' .. listLevel, ['bullet'] = '<br/>' .. listLevel, ['*'] = '<br/>' .. listLevel,
['to'] = ' to&nbsp;',
['and-list'] = '&#32;and<br/>' .. listLevel,
['br'] = '<br/>',
['or-list'] = '&#32;or<br/>' .. listLevel,
['newline'] = '<br/>',
['&-list'] = '&#32;&<br/>' .. listLevel, ['amp-list'] = '&#32;&<br/>' .. listLevel,
['list'] = '<br/>' .. listLevel,
['bullet'] = '<br/>' .. listLevel,
['*'] = '<br/>' .. listLevel,
['and-list'] = ' and<br/>' .. listLevel,
['or-list'] = ' or<br/>' .. listLevel,
['&-list'] = ' &<br/>' .. listLevel,
['amp-list'] = ' &<br/>' .. listLevel,
['comma-list'] = ',<br/>' .. listLevel,
['comma-list'] = ',<br/>' .. listLevel,
[',-list'] = ',<br/>' .. listLevel,
}
}
local midDelimiterValues = {
local midDelimiterValues = {
['and'] = '&#32;', ['&'] = '&#32;', ['amp'] = '&#32;',
['and'] = ', ',
['and-list'] = ',<br>\n' .. listLevel, ['&-list'] = ',<br>\n' .. listLevel,
['&'] = ', ',
['amp'] = ', ',
['and-list'] = ',<br>\n' .. listLevel,
['&-list'] = ',<br>\n' .. listLevel,
}
}


Line 50: Line 60:
for i,unit in ipairs(args) do
for i,unit in ipairs(args) do
if (i > 1) then
if (i > 1) then
local currentDelimiter = args[i+1] and midDelimiter or (serialDelimiter .. delimiter)
local currentDelimiter = args[i*1+1] and midDelimiter or (serialDelimiter .. delimiter)
output = output .. currentDelimiter .. tag(args[i])
output = output .. currentDelimiter .. tag(args[i])
end
end

Revision as of 03:40, 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'] = '<br/>' .. listLevel,
		 ['bullet'] = '<br/>' .. listLevel,
		 ['*'] = '<br/>' .. listLevel,
		['and-list'] = ' and<br/>' .. listLevel,
		['or-list'] = ' or<br/>' .. listLevel,
		['&-list'] = ' &<br/>' .. listLevel,
		['amp-list'] = ' &<br/>' .. listLevel,
		['comma-list'] = ',<br/>' .. listLevel,
		 [',-list'] = ',<br/>' .. listLevel,
	}
	
	local midDelimiterValues = {
		['and'] = ', ',
		 ['&'] = ', ',
		 ['amp'] = ', ',
		['and-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;'
	if finalDelimiterValues[delimiter] then delimiter = finalDelimiterValues[delimiter] end
	local midDelimiter = midDelimiterValues[delimiter] or delimiter
	local serialDelimiter = delimitersWithSerial[delimiter] and ',' or ''
	
	for i,unit in ipairs(args) do
		if (i > 1) then
			local currentDelimiter = args[i*1+1] and midDelimiter or (serialDelimiter .. delimiter)
			output = output .. currentDelimiter .. tag(args[i])
		end
	end
	
	return output
	
end

return p