Module:Delimited tag
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'] = ', ',
[','] = ', ',
['and'] = ' and ',
['&'] = ' & ',
['amp'] = ' & ',
['or'] = ' or ',
['to'] = ' to ',
['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 ' '
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