Module:Delimited tag: Difference between revisions
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/>', | ||
[' | ['comma'] = ', ', | ||
[','] = ', ', | |||
['&'] = ' | ['and'] = ' and ', | ||
['or'] = ' | ['&'] = ' & ', | ||
['to'] = ' | ['amp'] = ' & ', | ||
['br'] = '<br/>', ['newline'] = '<br/>', | ['or'] = ' or ', | ||
['list'] = '<br/>' .. listLevel, ['bullet'] = '<br/>' .. listLevel, ['*'] = '<br/>' .. listLevel, | ['to'] = ' to ', | ||
['and-list'] = ' | ['br'] = '<br/>', | ||
['or-list'] = ' | ['newline'] = '<br/>', | ||
['&-list'] = ' | ['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'] = ' | ['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'] = ', ',
[','] = ', ',
['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