Update formatting for wasm notebook · sheeeng/rustpython-rustpython@bdcdcb1 · GitHub
Skip to content

Commit bdcdcb1

Browse files
committed
Update formatting for wasm notebook
1 parent 4e5dc3e commit bdcdcb1

10 files changed

Lines changed: 313 additions & 306 deletions

File tree

Lines changed: 28 additions & 27 deletions

wasm/notebook/snippets/python-js-css/javascript.txt

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,39 @@
22

33
// Javascript code go here
44

5-
function create_ui() {
6-
7-
const input = document.createElement("input");
8-
input.type = "text";
9-
input.id = "input-1";
10-
document.getElementById("rp-notebook").appendChild(input);
11-
12-
const btn = document.createElement("button");
13-
btn.type = "button";
14-
btn.id = "btn-caclulate";
15-
btn.innerHTML = "click me";
16-
btn.addEventListener('click', calculate, false);
17-
document.getElementById("rp-notebook").appendChild(btn);
18-
19-
const div = document.createElement("div");
20-
div.id = "result";
21-
div.classList.add("result");
22-
document.getElementById("rp-notebook").appendChild(div);
23-
24-
}
25-
26-
function calculate() {
27-
28-
let target = document.getElementById("result");
29-
target.innerHTML = "";
30-
31-
let code = 'runModel()';
32-
33-
let input = document.getElementById("input-1").value;
34-
35-
let params = { "data": input };
36-
37-
38-
rp.pyExec(code, {
39-
stdout: (output) => {
40-
target.innerHTML += output;
41-
},
42-
vars: params
43-
});
44-
45-
}
5+
function create_ui() {
6+
const input = document.createElement('input');
7+
input.type = 'text';
8+
input.id = 'input-1';
9+
document.getElementById('rp-notebook').appendChild(input);
10+
11+
const btn = document.createElement('button');
12+
btn.type = 'button';
13+
btn.id = 'btn-caclulate';
14+
btn.innerHTML = 'click me';
15+
btn.addEventListener('click', calculate, false);
16+
document.getElementById('rp-notebook').appendChild(btn);
17+
18+
const div = document.createElement('div');
19+
div.id = 'result';
20+
div.classList.add('result');
21+
document.getElementById('rp-notebook').appendChild(div);
22+
}
23+
24+
function calculate() {
25+
let target = document.getElementById('result');
26+
target.innerHTML = '';
27+
28+
let code = 'runModel()';
29+
30+
let input = document.getElementById('input-1').value;
31+
32+
let params = { data: input };
33+
34+
rp.pyExec(code, {
35+
stdout: (output) => {
36+
target.innerHTML += output;
37+
},
38+
vars: params,
39+
});
40+
}

wasm/notebook/snippets/python-js-css/main.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
# RustPython Notebook: python, javascript, css, markdown and math
44

55

6-
Python in the browser is fun. Python and Javascript working together is double the fun 😜. Markdown and math are good for communicating ideas 🤔 (especially scientific ones). Adding css to the mix, makes everything look pretty ✨.
6+
Python in the browser is fun. Python and Javascript working together is double
7+
the fun 😜. Markdown and math are good for communicating ideas 🤔 (especially
8+
scientific ones). Adding css to the mix, makes everything look pretty ✨.
79

810
---
911

@@ -34,9 +36,9 @@ create_ui();
3436
# Python code
3537

3638
def runModel():
37-
input = js_vars['data']
38-
print ("<br>")
39-
print("A little javascript birdie told the python snake your lucky number 🙊")
40-
print ("Now the everyone knows that it is: " + str(input))
39+
input = js_vars['data']
40+
print ("<br>")
41+
print("A little javascript birdie told the python snake your lucky number 🙊")
42+
print ("Now the everyone knows that it is: " + str(input))
4143

4244

wasm/notebook/snippets/python-js.txt

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
# RustPython Notebook: python, javascript, css, markdown and math
44

5-
Python in the browser is fun 🤘. Python and Javascript working together is double the fun 😜. Markdown and math are good for communicating ideas 💡(especially scientific ones 🧠). Adding css to the mix, makes everything look pretty ✨.
5+
Python in the browser is fun 🤘. Python and Javascript working together is double
6+
the fun 😜. Markdown and math are good for communicating ideas 💡(especially
7+
scientific ones 🧠). Adding css to the mix, makes everything look pretty ✨.
68

79
# Main
810

@@ -13,7 +15,8 @@ In the notebook, you can write markdown, math, javascript and python.
1315
H(t) \xrightarrow{write} \Big[A(t+1),\ H(t+1)\Big]
1416

1517
%%md
16-
It even highlights properly. You can multi-task with split view mode and create python documents as you need to. In main, use `%%` then:
18+
It even highlights properly. You can multi-task with split view mode and create
19+
python documents as you need to. In main, use `%%` then:
1720
- `%%md` for markdown
1821
- `%%py` for python
1922
- `%%js` for javascript
@@ -40,10 +43,10 @@ Here is a run down of what is happening with this demo. The notebook:
4043
# Python code
4144

4245
def runModel():
43-
input = js_vars['data']
44-
print ("<br>")
45-
print("A little javascript birdie told the python snake your lucky number 🙊")
46-
print ("Now the everyone knows that it is: " + str(input))
46+
input = js_vars['data']
47+
print ("<br>")
48+
print("A little javascript birdie told the python snake your lucky number 🙊")
49+
print ("Now the everyone knows that it is: " + str(input))
4750

4851
%%md
4952
## Calculator
@@ -86,12 +89,12 @@ function calculate() {
8689
let params = { "data": input };
8790

8891

89-
rp.pyExec(code, {
90-
stdout: (output) => {
91-
target.innerHTML += output;
92-
},
93-
vars: params
94-
});
92+
rp.pyExec(code, {
93+
stdout: (output) => {
94+
target.innerHTML += output;
95+
},
96+
vars: params
97+
});
9598

9699
}
97100

@@ -102,12 +105,7 @@ create_ui();
102105
# Python code
103106

104107
def runModel():
105-
input = js_vars['data']
106-
print ("<br>")
107-
print("A little javascript birdie told the python snake your lucky number 🙊")
108-
print ("Now the everyone knows that it is: " + str(input))
109-
110-
111-
112-
113-
108+
input = js_vars['data']
109+
print ("<br>")
110+
print("A little javascript birdie told the python snake your lucky number 🙊")
111+
print ("Now the everyone knows that it is: " + str(input))

wasm/notebook/snippets/python-markdown-math.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ In the notebook, you can write markdown, math and python. use %% then:
1919
- math-inline for an inline math block
2020

2121

22-
I **can** bold things and _italicize_ them. You got the gist, this is standard markdown syntax that you can [google](google.com).
22+
I **can** bold things and _italicize_ them. You got the gist, this is standard
23+
markdown syntax that you can [google](google.com).
2324

2425
<br>
2526

wasm/notebook/src/editor.js

Lines changed: 17 additions & 15 deletions

0 commit comments

Comments
 (0)