No edit summary |
No edit summary |
||
Line 7: | Line 7: | ||
str._limit = function(s, len, suffix, lang) |
str._limit = function(s, len, suffix, lang) |
||
− | suffix = |
+ | if suffix == '' or not suffix then |
+ | suffix = ' ...' |
||
+ | end |
||
len = tonumber(len) or -1 |
len = tonumber(len) or -1 |
||
-- truncate |
-- truncate |
Revision as of 03:54, 16 January 2021
Documentation The documentation below is transcluded from Module:Test/doc. (edit | history)
A test module to avoid disturbing "real" pages.
See Terraria Wiki:Lua for more information about Lua and links to other help resources.
Feel free to test this module at Terraria Wiki:Sandbox.
local ustring = mw.ustring
local str = {}
-- for
local char_width = {
['zh'] = 2,
}
str._limit = function(s, len, suffix, lang)
if suffix == '' or not suffix then
suffix = ' ...'
end
len = tonumber(len) or -1
-- truncate
s = ustring.sub( s, 0, len )
-- word pruning
local s2 = ustring.match(s, '.+%s')
return (s2 or s) .. suffix;
end
str.limit = function(frame)
return str._limit(frame.args[1], frame.args[2], frame.args['suffix'], frame.args['lang'] )
end
return str