diff --git a/index.html b/index.html
index 00ac6c9..d5056aa 100644
--- a/index.html
+++ b/index.html
@@ -37,22 +37,24 @@
// Redirect Python's stdout and stderr to the console area
pyodide.runPython(`
- import sys
- import asyncio
- from js import document
+import sys
+import asyncio
+from js import document
- class ConsoleOutput:
- def write(self, text):
- console = document.getElementById("console")
- console.textContent += text
- console.scrollTop = console.scrollHeight # Auto-scroll to bottom
+class ConsoleOutput:
+ def write(self, text):
+ console = document.getElementById("console")
+
+ console.innerHTML += text.replace("\\n", "
") # Convert newlines to
+ console.scrollTop = console.scrollHeight # Auto-scroll to bottom
- def flush(self):
- pass
+ def flush(self):
+ pass
+
+sys.stdout = ConsoleOutput()
+sys.stderr = ConsoleOutput()
+`);
- sys.stdout = ConsoleOutput()
- sys.stderr = ConsoleOutput()
- `);
return pyodide;
}
@@ -80,8 +82,7 @@
return result;
}
- // Example usage
- const input = " Line 1\n Line 2\nLine 3";
+
const output = addExtraLineWithIndent(code, "await asyncio.sleep(0.01)");
console.log(output);