Skip to content

Commit bd8f471

Browse files
committed
Making repl link optional
1 parent 97896f4 commit bd8f471

File tree

4 files changed

+33
-83
lines changed

4 files changed

+33
-83
lines changed

_includes/default.njk

Lines changed: 1 addition & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,7 @@
11
---
22
layout: base.njk
33
---
4-
<<<<<<< HEAD
54

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

8-
{{ content | safe }}
9-
=======
10-
<!doctype html>
11-
<html lang="en">
12-
<head>
13-
<meta charset="utf-8">
14-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
15-
<title>{{ title }}</title>
16-
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Roboto:300,300italic,700,700italic">
17-
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.css">
18-
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/milligram/1.3.0/milligram.css">
19-
<link rel="stylesheet" href="{{ "/css/main.css" | url }}">
20-
<link rel="stylesheet"
21-
href="//cdn.jsdelivr.net/gh/highlightjs/cdn-release@9.16.2/build/styles/default.min.css">
22-
<script src="//cdn.jsdelivr.net/gh/highlightjs/cdn-release@9.16.2/build/highlight.min.js"></script>
23-
<script>
24-
hljs.initHighlightingOnLoad();
25-
</script>
26-
<script src="{{ "/js/main.js" | url }}"></script>
27-
</head>
28-
<body>
29-
<header class="container">
30-
<div class="row">
31-
<div class="column column-50">
32-
<h1 class="logo">
33-
<a href="/">ONAD Study Guide</a>
34-
</h1>
35-
</div>
36-
<div class="top-links column column-50">
37-
<ul>
38-
<li>
39-
<a href="https://training.linuxfoundation.org/certification/jsnad/" target="_blank" title="OpenJS Node.js Application Developer (JSNAD)">JSNAD Certification</a>
40-
</li>
41-
</ul>
42-
</div>
43-
</div>
44-
</header>
45-
<main class="container">
46-
<div class="row">
47-
<div class="sidebar column">
48-
<nav>
49-
<ul class="topics">
50-
{% for topic in topics %}
51-
<li data-topic="{{topic.url}}">
52-
<a href="{{ topic.url | url }}" {% if page.url === topic.url %} class="current" {% endif %}>{{topic.title}}</a>
53-
</li>
54-
{% endfor %}
55-
</ul>
56-
</nav>
57-
</div>
58-
<div class="main-content column column-75">
59-
<h1>{{ title }}</h1>
60-
{{ content | safe }}
61-
</div>
62-
</div>
63-
</main>
64-
<footer class="container">
65-
<div class="row">
66-
<div class="column column-75 column-offset-25">
67-
<p>
68-
<a href="https://github.com/Node-Study-Guide/openjs-nodejs-application-developer-study-guide/tree/master/{{ page.inputPath }}">Edit this page on GitHub</a>
69-
</p>
70-
</div>
71-
</div>
72-
73-
</footer>
74-
</body>
75-
</html>
76-
>>>>>>> Adapting repl code to apply to all code blocks automatically
7+
{{ content | safe }}

events/index.md

Lines changed: 11 additions & 3 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,14 +37,18 @@ eventEmitter.on('foo', foo);
3537
eventEmitter.emit('foo');
3638
```
3739

40+
</div>
41+
3842
## Passing parameters
3943

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

4246
For example:
4347

48+
<div class="repl-code">
49+
4450
```javascript
45-
const { EventEmitter } = require("events");
51+
const { EventEmitter } = require('events');
4652

4753
// create an emitter and bind some events to it
4854
const eventEmitter = new EventEmitter();
@@ -52,12 +58,14 @@ const foo = function foo(bar) {
5258
};
5359

5460
// Bind the connection event with the listner1 function
55-
eventEmitter.on("foo", foo);
61+
eventEmitter.on('foo', foo);
5662

5763
// fire the event
58-
eventEmitter.emit("foo", "bar");
64+
eventEmitter.emit('foo', 'bar');
5965
```
6066

67+
</div>
68+
6169
## Summary
6270

6371
Listeners _listen_ for events, that are _emitted_ from emitters.

js/main.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
11
/* Add an edit in repl link to code blocks */
22

33
function checkForReplLinks() {
4-
const replCode = document.querySelectorAll('pre');
5-
[...replCode].forEach(pre => {
6-
console.log(pre);
7-
const text = encodeURI(pre.innerText);
4+
// const replCode = document.querySelectorAll('pre');
5+
// [...replCode].forEach(pre => {
6+
// console.log(pre);
7+
// const text = encodeURI(pre.innerText);
8+
// const link = document.createElement('a');
9+
// link.title = 'Run this code in the REPL';
10+
// link.innerText = 'Run this code in the REPL';
11+
// link.href = '/repl/?code=' + text;
12+
// const paragraph = document.createElement('p');
13+
// paragraph.appendChild(link);
14+
// const wrapper = document.createElement('div');
15+
// pre.parentNode.insertBefore(wrapper, pre);
16+
// wrapper.appendChild(pre);
17+
// wrapper.appendChild(paragraph);
18+
// });
19+
const replCode = document.querySelectorAll('.repl-code');
20+
[...replCode].forEach(code => {
21+
const codeText = encodeURI(code.innerText);
822
const link = document.createElement('a');
923
link.title = 'Run this code in the REPL';
1024
link.innerText = 'Run this code in the REPL';
11-
link.href = '/repl/?code=' + text;
25+
link.href = '/repl/?code=' + codeText;
1226
const paragraph = document.createElement('p');
1327
paragraph.appendChild(link);
14-
const wrapper = document.createElement('div');
15-
pre.parentNode.insertBefore(wrapper, pre);
16-
wrapper.appendChild(pre);
17-
wrapper.appendChild(paragraph);
28+
code.appendChild(paragraph);
1829
});
1930
}
2031

repl/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
layout: default.njk
2+
layout: default
33
title: Node.js REPL
44
---
55

0 commit comments

Comments
 (0)