Module:Delimited tag: Difference between revisions
Jump to navigation
Jump to search
Create module version of Template:Code |
init p |
||
Line 1: | Line 1: | ||
local p = {} | |||
function p.output(f) | function p.output(f) | ||
Revision as of 03:32, 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/>',
[','] = ', ',
['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,
}
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
local currentDelimiter = args[i+1] and midDelimiter or (serialDelimiter .. delimiter)
output = output .. currentDelimiter .. tag(args[i])
end
end
return p