Skip to content

Commit df94b8d

Browse files
committed
Adding repl
1 parent 8735407 commit df94b8d

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

_includes/default.njk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
---
22
layout: base.njk
3-
templateClass: tmpl-post
43
---
54

65
<h1>{{ title }}</h1>

events/index.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ When the EventEmitter object emits an event, all of the functions attached to th
1616

1717
This example creates an event listener for `foo` events, and an event emitter to fire these events.
1818

19+
<div class="repl-code">
20+
1921
```javascript
2022
const { EventEmitter } = require('events');
2123

@@ -35,6 +37,23 @@ eventEmitter.on('foo', foo);
3537
eventEmitter.emit('foo');
3638
```
3739

40+
</div>
41+
42+
<script>
43+
// TODO - move to main.js when other PRs merged
44+
const replCode = document.querySelectorAll('.repl-code');
45+
[...replCode].forEach(code => {
46+
const codeText = encodeURI(code.innerText);
47+
const link = document.createElement('a');
48+
link.title = "Run this code in the REPL";
49+
link.innerText = "Run this code in the REPL";
50+
link.href = "/repl/?code=" + codeText;
51+
const paragraph = document.createElement('p');
52+
paragraph.appendChild(link);
53+
code.appendChild(paragraph);
54+
});
55+
</script>
56+
3857
## Passing parameters
3958

4059
When an event is emitted using the `emit` method, the subsequent arguments are passed through to the listeners.

repl/index.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
layout: default.njk
3+
title: Node.js REPL
4+
---
5+
6+
Use this space to try out code from the examples!
7+
8+
<script src="https://embed.runkit.com"></script>
9+
10+
<div id="repl"></div>
11+
12+
<script>
13+
14+
const urlParams = new URLSearchParams(window.location.search);
15+
const code = urlParams.get('code');
16+
17+
const notebook = RunKit.createNotebook({
18+
element: document.getElementById("repl"),
19+
source: code || "// Your JavaScript code goes here",
20+
minHeight: "500px",
21+
});
22+
23+
</script>

0 commit comments

Comments
 (0)