Skip to content

Commit afd0eea

Browse files
committed
feat: add interactive Python code editor for tutorials
- Monaco Editor + Pyodide integration for browser-based Python execution - MDX component for easy tutorial integration - Added example to Python intro tutorial Fixes #1128
1 parent 993d939 commit afd0eea

File tree

8 files changed

+671
-1
lines changed

8 files changed

+671
-1
lines changed

docs/python/intro-python.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Here is a simple Python program that prints "Hello, World!":
4545

4646
```python
4747
print("Hello, World!")
48-
````
48+
```
4949

5050
Output:
5151

@@ -55,6 +55,27 @@ Hello, World!
5555

5656
You can run this code in any Python interpreter, and it will display the message on the screen.
5757

58+
### Try Python Interactive Code Editor
59+
60+
Try running Python code directly in your browser! Edit the code below and click "Run" to see the output:
61+
62+
<PythonCodeEditor code={`# Try editing this Python code!
63+
print("Hello, World!")
64+
print("Welcome to Python!")
65+
66+
# You can also try:
67+
name = "Python Learner"
68+
print(f"Hello, {name}!")
69+
70+
# Mathematical operations
71+
result = 2 + 3 * 4
72+
print(f"2 + 3 * 4 = {result}")
73+
74+
# Lists and loops
75+
fruits = ["apple", "banana", "orange"]
76+
for fruit in fruits:
77+
print(f"I like {fruit}s")`} />
78+
5879

5980
### Good to know
6081

package-lock.json

Lines changed: 99 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"@floating-ui/react": "^0.27.8",
3939
"@giscus/react": "^3.1.0",
4040
"@mdx-js/react": "^3.0.0",
41+
"@monaco-editor/react": "^4.7.0",
4142
"@popperjs/core": "^2.11.8",
4243
"@radix-ui/react-avatar": "^1.1.7",
4344
"@radix-ui/react-collapsible": "^1.1.12",
@@ -57,6 +58,7 @@
5758
"framer-motion": "^12.7.5",
5859
"lucide-react": "^0.503.0",
5960
"prism-react-renderer": "^2.3.0",
61+
"pyodide": "^0.29.0",
6062
"react": "^18.3.1",
6163
"react-dom": "^18.3.1",
6264
"react-icons": "^5.5.0",

0 commit comments

Comments
 (0)