Module:Delimited tag: Difference between revisions
Jump to navigation
Jump to search
more user-friendly error |
seems this doesn't break anything; don't mind the uhhh... ternary expression |
||
(2 intermediate revisions by 2 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 '**' | ||
Line 19: | Line 19: | ||
['comma'] = ', ', | ['comma'] = ', ', | ||
[','] = ', ', | [','] = ', ', | ||
['and'] = ' and ', | ['and'] = ', and ', | ||
['&'] = ' & ', | ['&'] = ' & ', | ||
['or'] = ' or ', | ['or'] = ' or ', | ||
['to'] = ' to ', | ['to'] = ' to ', | ||
['br'] = '<br/>', | ['br'] = '<br/>', | ||
['newline'] = '<br>', | ['newline'] = '<br/>', | ||
['list'] = '\n' .. listLevel, | ['list'] = '\n' .. listLevel, | ||
['bullet'] = '\n' .. listLevel, | ['bullet'] = '\n' .. listLevel, | ||
Line 39: | Line 39: | ||
['&'] = ', ', | ['&'] = ', ', | ||
['or'] = ', ', | ['or'] = ', ', | ||
['and-list'] = ',<br>\n' .. listLevel, | ['and-list'] = ',<br/>\n' .. listLevel, | ||
['&-list'] = ',<br>\n' .. listLevel, | ['&-list'] = ',<br/>\n' .. listLevel, | ||
['or-list'] = ',<br>\n' .. listLevel, | ['or-list'] = ',<br/>\n' .. listLevel, | ||
} | } | ||
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 ',
['&'] = ' & ',
['or'] = ' or ',
['to'] = ' to ',
['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 ' '
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