Module:Delimited tag: Difference between revisions

From Modded Wiki
Jump to navigation Jump to search
skip first go-around
seems this doesn't break anything; don't mind the uhhh... ternary expression
 
(7 intermediate revisions by 4 users not shown)
Line 9: Line 9:


local tag = function(txt)
local tag = function(txt)
return '<' .. args['tag'] .. '>' .. txt .. '</' .. args['tag'] .. '>'
return '<' .. args['tag'] .. (args['wordbreak'] and ' style="word-break:break-all"' or '') .. '>' .. txt .. '</' .. args['tag'] .. '>'
end
end
local listLevel = args['list-level'] or '**'
local listLevel = args['list-level'] or '**'


local output = tag(args[1])
local output = tag(assert(args[1], 'No tag text provided.?'))
local finalDelimiterValues = {
local finalDelimiterValues = {
['none'] = '<nowiki/>',
['none'] = '<nowiki/>',
[','] = ',&#32;',
['comma'] = ', ',
['and'] = '&#32;and&#32;',
[','] = ', ',
['&'] = '&nbsp;&amp;&nbsp;', ['amp'] = '&nbsp;&amp;&nbsp;',
['and'] = ', and ',
['or'] = '&#32;or&nbsp;',
['&'] = ' &amp;&nbsp;',
['to'] = '&#32;to&nbsp;',
['or'] = ' or&nbsp;',
['br'] = '<br/>', ['newline'] = '<br/>',
['to'] = ' to&nbsp;',
['list'] = '<br/>' .. listLevel, ['bullet'] = '<br/>' .. listLevel, ['*'] = '<br/>' .. listLevel,
['br'] = '<br/>',
['and-list'] = '&#32;and<br/>' .. listLevel,
['newline'] = '<br/>',
['or-list'] = '&#32;or<br/>' .. listLevel,
['list'] = '\n' .. listLevel,
['&-list'] = '&#32;&<br/>' .. listLevel, ['amp-list'] = '&#32;&<br/>' .. listLevel,
['bullet'] = '\n' .. listLevel,
['comma-list'] = ',<br/>' .. listLevel,
['*'] = '\n' .. listLevel,
['and-list'] = ', and\n' .. listLevel,
['or-list'] = ', or\n' .. listLevel,
['&-list'] = ' &\n' .. listLevel,
['comma-list'] = ',\n' .. listLevel,
[',-list'] = ',\n' .. listLevel,
}
}
local midDelimiterValues = {
local midDelimiterValues = {
['and'] = '&#32;', ['&'] = '&#32;', ['amp'] = '&#32;',
['and'] = ', ',
['and-list'] = ',<br>\n' .. listLevel, ['&-list'] = ',<br>\n' .. listLevel,
['&'] = ', ',
}
['or'] = ', ',
 
['and-list'] = ',<br/>\n' .. listLevel,
local delimitersWithSerial = {
['&-list'] = ',<br/>\n' .. listLevel,
['and'] = true,
['or-list'] = ',<br/>\n' .. listLevel,
['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 finalDelimiter
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] 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

Latest revision as of 01:37, 18 March 2024

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'] .. (args['wordbreak'] and ' style="word-break:break-all"' or '') .. '>' .. txt .. '</' .. args['tag'] .. '>'
	end
	local listLevel = args['list-level'] or '**'

	local output = tag(assert(args[1], 'No tag text provided.?'))
	
	local finalDelimiterValues = {
		['none'] = '<nowiki/>',
		['comma'] = ', ',
		 [','] = ', ',
		['and'] = ', and ',
		['&'] = ' &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,
		['comma-list'] = ',\n' .. listLevel,
		 [',-list'] = ',\n' .. listLevel,
	}
	
	local midDelimiterValues = {
		['and'] = ', ',
		 ['&'] = ', ',
		 ['or'] = ', ',
		['and-list'] = ',<br/>\n' .. listLevel,
		 ['&-list'] = ',<br/>\n' .. listLevel,
		 ['or-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 finalDelimiter
	
	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