UNPKG

webcodeviewer

Version:

WebCodeViewer is a powerful npm package that allows you to easily view code snippets and source files directly in the web browser.

33 lines (25 loc) 698 B
const { spawn } = require('child_process'); function executePythonCode(code, outputElement) { // Spawns a Python process const pythonProcess = spawn('python', ['-c', code]); // Pipes Python process output to the output element pythonProcess.stdout.on('data', (data) => { outputElement.innerHTML = data.toString(); }); } function runPythonCode(code, outputElement) { const codeToExecute = ` ${code} `; executePythonCode(codeToExecute, outputElement); } export const code = { run: { html(code, output) { output.innerHTML = code; }, py(code, output){ runPythonCode(code, output) } } };