Module:Command: Difference between revisions
mNo edit summary |
mNo edit summary |
||
| (10 intermediate revisions by 4 users not shown) | |||
| Line 40: | Line 40: | ||
local startPos, endPos = params[1]:find( "'[^']-'" ) | local startPos, endPos = params[1]:find( "'[^']-'" ) | ||
local startPosn, endPosn = params[1]:find('"[^"]-"') | local startPosn, endPosn = params[1]:find('"[^"]-"') | ||
if | if startPosn and startPos and startPosn < startPos then | ||
startPos, endPos = startPosn, endPosn | startPos, endPos = startPosn, endPosn | ||
end | end | ||
| Line 58: | Line 58: | ||
if startPos then | if startPos then | ||
params[1] = params[1]:sub( 1, startPos - 1 ) .. | params[1] = params[1]:sub( 1, startPos - 1 ) .. | ||
params[1]:sub( startPos, endPos ):gsub('%[','〈lsqb〉'):gsub('%]','〈rsqb〉'):gsub('{','& | params[1]:sub( startPos, endPos ):gsub('%[','〈lsqb〉'):gsub('%]','〈rsqb〉'):gsub('{','{'):gsub('}','}'):gsub("'",'〈apos〉'):gsub('"','〈quot〉'):gsub( '%s', '〈space〉' ) .. | ||
params[1]:sub( endPos + 1 ) | params[1]:sub( endPos + 1 ) | ||
else | else | ||
| Line 83: | Line 83: | ||
break | break | ||
end | end | ||
if params[param] ~= '' and params[param]~='?' then | if params[param] and params[param] ~= '' and params[param]~='?' then | ||
hasValue = false | hasValue = false | ||
for k,j in pairs(v) do | for k,j in pairs(v) do | ||
if j == params[param] or j:match('<.+>') then | if j == params[param] or j:match('<.+>') then | ||
table.insert(section, | table.insert(section, params[param]) | ||
hasValue=true | hasValue=true | ||
if k=='redirect' then | if k=='redirect' then | ||
| Line 175: | Line 175: | ||
local attr = '' | local attr = '' | ||
if args.long then | if args.long then | ||
attr = 'style="display: | attr = 'style="display: flex; padding: 0.8em 1em; margin-bottom: 0.4em; word-warp: break-word;"' | ||
end | end | ||
local result = table.concat( command, ' ' ):gsub( '〈space〉', ' ' ):gsub('〈lsqb〉', '%['):gsub('〈rsqb〉', '%]') | local result = table.concat( command, ' ' ):gsub( '〈space〉', ' ' ):gsub('〈lsqb〉', '%['):gsub('〈rsqb〉', '%]'):gsub('〈apos〉',"'"):gsub('〈quot〉','"') | ||
-- Don't encode if told not to or if there is a sub-command | -- Don't encode if told not to or if there is a sub-command | ||
if args.escape ~= '0' then | if args.escape ~= '0' then | ||
result = result:gsub( '<', '<' ):gsub( '<(!%-%- | result = result:gsub( '<', '<' ):gsub( '<(!%-%- Command %-%->)<','<%1<'):gsub( '</code><(!%-%- /Command %-%->)','</code><%1') | ||
end | end | ||
result = '<!-- Command --><code ' .. attr .. '><span>' .. slash .. result .. '</span></code><!-- /Command -->' | |||
if needFormat then | |||
result = result .. '[[Category:Pages using deprecated command module]]' | |||
end | |||
return result | |||
end | end | ||
return p | return p | ||