Module:Command: Difference between revisions

No edit summary
mNo edit summary
 
(9 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 startPos and startPos and startPosn < startPos then
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('{','&lcub;'):gsub('}','&rcub;'):gsub("'",'&apos;'):gsub('"','&quot;'):gsub( '%s', '〈space〉' ) ..
params[1]:sub( startPos, endPos ):gsub('%[','〈lsqb〉'):gsub('%]','〈rsqb〉'):gsub('{','&#123;'):gsub('}','&#125;'):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, j)
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: block; padding: 0.8em 1em; margin-bottom: 0.4em; word-warp: break-word;"'
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〉', '%]'):gsub( '</?nowiki%s*/?%s*>','')  
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( '<', '&lt;' ):gsub( '&lt;(!%-%- /?Command %-%->)','<%1')
result = result:gsub( '<', '&lt;' ):gsub( '&lt;(!%-%- Command %-%->)&lt;','<%1<'):gsub( '&lt;/code>&lt;(!%-%- /Command %-%->)','</code><%1')
end
end
return '<!-- Command --><code ' .. attr .. '>' .. slash .. result .. '</code><!-- /Command -->'
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