Module:Command: Difference between revisions
Smartly handle spaces and dataTags |
Auto escape sub-commands |
||
| Line 10: | Line 10: | ||
if not fullCommand and v == '...' then | if not fullCommand and v == '...' then | ||
fullCommand = true | fullCommand = true | ||
elseif i > 1 or v ~= commandName then | elseif i > 1 or v:match( '^%s*/?(.+)' ):lower() ~= commandName then | ||
-- Don't encode sub- | -- Don't encode if told not to or if there is a sub-command | ||
if not v:find( ' | if args.encode ~= '0' and not v:find( '<!%-%- Command %-%->' ) then | ||
v = | v = v:gsub( '<', '<' ) | ||
end | end | ||
table.insert( command, mw.text.trim( v ) ) | table.insert( command, mw.text.trim( v ) ) | ||
end | end | ||
end | end | ||
if #command == 1 and ( not args[2] or args[2] == '...' ) and command[1]:find( '%s' ) then | if #command == 1 and ( not args[2] or args[2] == '...' ) and command[1]:find( '%s' ) then | ||
local | local startPos, endPos = command[1]:find( '{.+}' ) | ||
if | if not startPos then | ||
command[1] = command[1]:sub( 1, | startPos, endPos = command[1]:find( '<!%-%- Command %-%->.+<!%-%- /Command %-%->' ) | ||
command[1]:sub( | end | ||
command[1]:sub( | |||
if startPos then | |||
command[1] = command[1]:sub( 1, startPos ) .. | |||
command[1]:sub( startPos + 1, endPos - 1 ):gsub( '%s', ' ' ) .. | |||
command[1]:sub( endPos ) | |||
end | end | ||
| Line 88: | Line 93: | ||
end | end | ||
if args. | local attr | ||
if args.long == '1' then | |||
attr = 'style="display:block;padding:0.8em 1em;margin-bottom:0.4em;word-wrap:break-word"' | |||
else | else | ||
attr = 'class="nowrap"' | |||
end | end | ||
return '<!-- Command --><code ' .. attr .. '>' .. slash .. table.concat( command, ' ' ):gsub( ' ', ' ' ) .. '</code><!-- /Command -->' | |||
end | end | ||
return p | return p | ||