Module:TerminalCommandGenerator: Difference between revisions

From iPhone Development Wiki
No edit summary
m (Trying a fix for newlines in command output)
Line 10: Line 10:
         else
         else
             if i % 2 == 0 then
             if i % 2 == 0 then
                 html = html .. '<p class="term-command">' .. command .. '</p>\n'
                 html = html .. '<p class="term-command">' .. mw.text.nowiki(command):gsub('\n', '<br>') .. '</p>\n'
             else
             else
                 html = html .. '<p class="term-output">' .. command .. '</p>\n'
                 html = html .. '<p class="term-output">' .. mw.text.nowiki(command):gsub('\n', '<br>') .. '</p>\n'
             end
             end
         end
         end

Revision as of 13:49, 7 October 2023

Documentation for this module may be created at Module:TerminalCommandGenerator/doc

local p = {}


function p.generateHtml(frame)
    local commands = frame:getParent().args
    local html = '<div class="terminal-' .. commands[1] .. '"><div class="term-bar"><div class="term-red"></div><span class="term-yellow"></span><span class="term-green"></span></div><div class="term-screen"><div class="term-commands">'
    for i, command in ipairs(commands) do
        if i == 1 then
            html = html
        else
            if i % 2 == 0 then
                html = html .. '<p class="term-command">' .. mw.text.nowiki(command):gsub('\n', '<br>') .. '</p>\n'
            else
                html = html .. '<p class="term-output">' .. mw.text.nowiki(command):gsub('\n', '<br>') .. '</p>\n'
            end
        end
    end
    html = html .. '</div></div></div>'
    return html
end

return p